User talk:Bastl

From RTwiki
Jump to: navigation, search

I'm interested in porting some RT techniques to linux.
This techniques are reachable from user space or are designed for user space processes, threads; e.g on SMP platforms.

  1. Suspend for count schedule cycles
    A process's suspend flag can be set to a value (32 or 64 bit) greater than 0.
    If that is done the scheduler compares each time if that flag equals 0 and decreases that flag.
    If the flag is 0 then there are some possibilities:
    1. Restore the flag to the set value, stop scheduling and call that process. On return the scheduler continues.
      The scheduler counts its IRQs and if the process does not return in a given time that process is closed with an error.
    2. The flag is not restored then all the same like above.
      After return the scheduler returns to normal mode
    3. The flag is not restored and the scheduler returns to normal mode and continues scheduling that process out of mind if the schedule time is enough for that process to full proceed

    This means a process can sleep for one or more system cycles. Because there is minimum one cycle between, the system can always do its tasks.
    Schedule cycles are the smallest time grid of a system and can be handled synchronous. If a process wants to suspend for a special delay a not synchronous mechanism have to be used that can cause jerking. Only with system's time base a smooth run can granted.
    Because of synchronism the programmer can calculate its environment and can imagine what the system does during that sleep. that results in much less timing errors and work arounds.
    Only the process it self or a process with root privileges can set this suspend value. Because the process its self can set its value only though an interrupt, there has to be an additional interrupt subrutin of INT 80h or 81h - see below.
    How long a system cycle is could be made publik over the sys file system or with an INT 80h or 81h (subrutine specifications)




  2. HPET RT user space functionality (all additional timers - not the first 3 of a HPET-chip)
    To support the HPET for user space there is a new interrupt implementation needed.
    Because the HPET can be very fast and the system interrupt (INT 80h) is so big there has to be a second interrupt maybe INT 81h only for the HPET (or other timers).

    INT 81h sub-routines
    rax Description
    0x00 change comparator value

    rdx = ID
    rcx = comparator value

    It takes one interrupt to set the value. So the next sycle is done with the old value if this call is done from inside the timer interrupt.

    return:
    rax = 0 on success or negative error code

    0x01 timer stop

    rdx = ID

    return:
    rax = 0 on success or negative error code

    0x02 timer restart

    rdx = ID

    return:
    rax = 0 on success or negative error code

    0x03 timer request

    rbx = call value of user space interrupt routine
    rcx = comparator value; shortest period possible get used.
    rdx = fault level (0..15), maximum fault interrupts are allowed. default = 0

    The first occurence of this timer interrupt (UIR call) is faster or equal to the given comparator value.

    return:
    rax = ID on success or negative error code
    ID : bit 0..7 = timer number, bit 8..15 = number of active timers, including this

    0x04 free timer - needed to proceed exit of the user space app.

    rdx = ID

    0x05 Specifications

    rdx = ID

    return:
    rax = Specifications: (or negative error code)

    bit value description
    0 1

    0

    HPET is present and is used

    INT 81h is disabled (or the free timer of the second PIT is used as option)

    1..10 xxxxxxxxx Timer frequency in MHz so max. interrupt frequency is timer MHZ / 2
    11 1

    0

    Interrupt via FSB / Hyper-Bus is used (SMI mechanism)

    APIC is used - ATTENTION! this can cause an APIC overload with fast values and so a SMI that will do a big break

    12..15 xxxx Timer interrupt faults. This indicates how often this interrupt wanted to call its UIR while that has not yet returend.

    A value of 15 (0xF) or given value by fault level is handled as error and this UIR is cleared and this timer freed.
    This value is also loaded to rax before the UIR is called.



    The System Interrupt Routine (SIR) of the timers
    There is one SIR for all timers. If a user space programm registers a function to be the User space Interrupt Routine (UIR) its call value is stored into an array together with a flag of this form:

    Type of a user space interrupt routine (UIR)
    type bit description
    int

    or
    long int

    0..31

    or
    0..63

    Call value of the user space function (UIR).

    Platform dependent.

    int 0..3
    The value of this four bits mirror the interrupts for this UIR while it has not yet returned.

    On return this value is decremented and on interrupt occurence increased.
    Each time this value is compared to be smaler as the fault level.





  3. Core/processor manager RT option (only for SMP platforms)
    There a core/processor manager of a scheduler can free a core/processor on a SMP platform that it can be used by a one and only RT application.
    If such a core/processor gets a RT flag the scheduler doesn't schedule that core/processor any more. So the RT applikation can run wihtout breaks.
    A big effort of doing so is that there is no multitasking functionality be missing. The RT core/processor application can call into multitasking cores/processors that are scheduled normal. Qt f.e. is so working for the RT application, too.
    Nevertheless RT applications often need a timer for special tasks, so HPET timers support (2.) is also needed here.
Personal tools