Measure the time during which a task takes 2 points in linux (task profiling)

I will soon start banging my head on the wall:

It is very simple, I want to measure the time during which the task takes 2 points (in Linux - 1 core - 1 processor). During this time, the task should have full control over the CPU and should NOT be interrupted by any other task or HW interruptions.

To achieve this, I created a kernel module to ensure that the above criteria are met. In this kernel module, I tried:

First disable IRQ:

  • I used spin_lock_irqsave () / spin_lock_irqrestore () - I suppose this is the right way to make sure that all local interrupts are disabled and my task has a processor for it in the critical area.

Then

  • Preempt_disable () is used → Since current = my task, the kernel should continue to execute my task logically until I turn on preemption → Does not work (my_task-> nvcsw and my_task-> nivcsw show that csw has happened → my task was unloaded)

I tried to increase the priority of my task by changing my_task-> prio and my_task-> static_prio to 1 → the highest real-time priority (my_task-> policy = SCHED_FIFO) ...

Doesn't work (my_task-> nvcsw and my_task-> nivcsw show that csw happened → my-task got preempted), and my_task-> prio got a new prio (120) scheduler, which I assume ...

- , / Linux? ( 50-500us) ?

/ (, , / procfs ):

// Handle request
switch( enable ){
    // Disable OS
    case COS_OS_DISABLE:
                    // Disable preemption
                    preempt_disable()
        // Save policy
        last_policy         = pTask->policy;
        // Save task priorities
        last_prio       = pTask->prio;
        last_static_prio    = pTask->static_prio;
        last_normal_prio    = pTask->normal_prio;
        last_rt_priority    = pTask->rt_priority;
        // Set priorities to highest real time prio 
        pTask->prio         = 1;
        pTask->static_prio  = 1;
        pTask->normal_prio  = 1;
        pTask->rt_priority  = 1;
        // Set scheduler policy to FIFO
        pTask->policy       = SCHED_FIFO;
        // Lock kernel: It will disable interrupts _locally_, but the spinlock itself will guarantee the global lock, so it will guarantee that there is only one thread-of-control within the region(s) protected by that lock.
        spin_lock_irqsave( &mr_lock , flags );
        break;
    // Default: Enable OS always
    case COS_OS_ENABLE:
    default:
        // Reset task priorities
        pTask->prio         = last_prio;
        pTask->static_prio  = last_static_prio;
        pTask->normal_prio  = last_normal_prio;
        pTask->rt_priority  = last_rt_priority;
        // Reset scheduler policy
        pTask->policy       = last_policy;
        // Unlock kernel
        spin_unlock_irqrestore( &mr_lock , flags );
                    // Enable preemption
                    preempt_enable();
        break;
}
+3
1

. .

, , u modifer of perf, ; - .

+1

All Articles