bug in Real-Time Preemption
Quoted 11 lines
I tried to your program: I couldn't make it fail under
PREEMPT_RT. No
matter what the termination value for the while loop in the priority 10 thread I put in the priority 50 thread printed the same "Dif:". I also put in a global variable,thread_done, which I set in the priority 10 thread after the loop and printed it out along with "Dif:". It was not set. I also tried to add exit(1) at the end of the priority 10 thread...I see no odd behaviour.
Esben
Look at my results:
I added a flag too.
under non RT preempt:
(these results are expected)
./a.out
Flag: 0, Dif:11714
./a.out
Flag: 0, Dif:11678
under full RT preempt:
./a.out
Flag: 1, Dif:582536
./a.out
Flag: 1, Dif:579791
This shows that thread with bigger priority was
blocked by the thread with lower priority!
Please, try it again with 'while (1) {' (or some much bigger number) instead of original 'while (i < 10000) {'.
Thanks,
Milan
Quoted 400 lines · Milan Svoboda
Quoted 4 lines
Hello all,
I have a test program which creates one thread with
SCHED_RRandpriority 50. This
Quoted 1 line
thread creates another thread witch
SCHED_RRand priority 10 and thenwaits some time
Quoted 1 line
until it exits. Thread with priority of 10 only counts, it should be a
cpu-hog and calls
sched_yield.Quoted 2 lines
Problem is that the parent thread (with priority 50) sleeps as long as
the thread with priority 10 is
Quoted 1 line
runnig when runnig on realtime-preempt-2.6.12-rc6-V0.7.48-01 with full
preemption enabled.
Quoted 2 lines
I tested this program on 2.4.21-xxx and on 2.6.12-rc6 with
realtime-preempt-2.6.12-rc6-V0.7.48-01 with RT preemption
Quoted 1 line
disabled and results were as expected - parent thread sleeps shorter
time then counting thread so program is
Quoted 371 lines
terminated before counting thread could finished it's work.
#include <
pthread.h>
#include <unistd.h>
#include <sys/time.h>void* thread(void *thread) { int i; while (i < 10000) { sched_yield(); i++; } }void* thread_main(void *arg) { pthread_attr_t attr; pthread_t p; struct sched_param sch; struct timeval tv1, tv2; unsigned int dif; pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_RR); sch.sched_priority = 10; pthread_attr_setschedparam(&attr, &sch); pthread_create(&p, &attr, thread, NULL); pthread_attr_destroy(&attr); gettimeofday(&tv1, NULL); usleep(10000); gettimeofday(&tv2, NULL); dif = (tv2.tv_sec - tv1.tv_sec) * 1000000 + tv2.tv_usec - tv1.tv_usec; printf("Dif: %d\n", dif); exit(0); }int main(int argc, char** argv) { pthread_attr_t attr; pthread_t p; struct sched_param sch; pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_RR); sch.sched_priority = 50; pthread_attr_setschedparam(&attr, &sch); pthread_create(&p, &attr, thread_main, NULL); pthread_attr_destroy(&attr); while (1) { sleep(500); } return 0; }Follows important parts from .config:
.config with RT preemption disabled
#
# General setup
#CONFIG_LOCALVERSION=""CONFIG_SWAP=yCONFIG_SYSVIPC=yCONFIG_POSIX_MQUEUE=yCONFIG_BSD_PROCESS_ACCT=y
#CONFIG_BSD_PROCESS_ACCT_V3is not setCONFIG_SYSCTL=y
#CONFIG_AUDITis not setCONFIG_HOTPLUG=yCONFIG_KOBJECT_UEVENT=y
#CONFIG_IKCONFIGis not set
#CONFIG_EMBEDDEDis not setCONFIG_KALLSYMS=yCONFIG_KALLSYMS_ALL=y
#CONFIG_KALLSYMS_EXTRA_PASSis not setCONFIG_PRINTK=yCONFIG_BUG=yCONFIG_BASE_FULL=yCONFIG_FUTEX=yCONFIG_EPOLL=yCONFIG_SHMEM=yCONFIG_CC_ALIGN_FUNCTIONS=0CONFIG_CC_ALIGN_LABELS=0CONFIG_CC_ALIGN_LOOPS=0CONFIG_CC_ALIGN_JUMPS=0
#CONFIG_TINY_SHMEMis not setCONFIG_BASE_SMALL=0#
# Loadable module support
#CONFIG_MODULES=yCONFIG_MODULE_UNLOAD=yCONFIG_MODULE_FORCE_UNLOAD=yCONFIG_OBSOLETE_MODPARM=yCONFIG_MODVERSIONS=y
#CONFIG_MODULE_SRCVERSION_ALLis not setCONFIG_KMOD=y#
# Processor type and features
#CONFIG_X86_PC=y
#CONFIG_X86_ELANis not set
#CONFIG_X86_VOYAGERis not set
#CONFIG_X86_NUMAQis not set
#CONFIG_X86_SUMMITis not set
#CONFIG_X86_BIGSMPis not set
#CONFIG_X86_VISWSis not set
#CONFIG_X86_GENERICARCHis not set
#CONFIG_X86_ES7000is not set
#CONFIG_M386is not set
#CONFIG_M486is not set
#CONFIG_M586is not set
#CONFIG_M586TSCis not set
#CONFIG_M586MMXis not setCONFIG_M686=y
#CONFIG_MPENTIUMIIis not set
#CONFIG_MPENTIUMIIIis not set
#CONFIG_MPENTIUMMis not set
#CONFIG_MPENTIUM4is not set
#CONFIG_MK6is not set
#CONFIG_MK7is not set
#CONFIG_MK8is not set
#CONFIG_MCRUSOEis not set
#CONFIG_MEFFICEONis not set
#CONFIG_MWINCHIPC6is not set
#CONFIG_MWINCHIP2is not set
#CONFIG_MWINCHIP3Dis not set
#CONFIG_MGEODEGX1is not set
#CONFIG_MCYRIXIIIis not set
#CONFIG_MVIAC3_2is not setCONFIG_X86_GENERIC=yCONFIG_X86_CMPXCHG=yCONFIG_X86_XADD=yCONFIG_X86_L1_CACHE_SHIFT=7CONFIG_GENERIC_CALIBRATE_DELAY=yCONFIG_X86_PPRO_FENCE=yCONFIG_X86_WP_WORKS_OK=yCONFIG_X86_INVLPG=yCONFIG_X86_BSWAP=yCONFIG_X86_POPAD_OK=yCONFIG_X86_GOOD_APIC=yCONFIG_X86_INTEL_USERCOPY=yCONFIG_X86_USE_PPRO_CHECKSUM=yCONFIG_HPET_TIMER=yCONFIG_HPET_EMULATE_RTC=y
#CONFIG_SMPis not setCONFIG_PREEMPT_NONE=y
#CONFIG_PREEMPT_VOLUNTARYis not set
#CONFIG_PREEMPT_DESKTOPis not set
#CONFIG_PREEMPT_RTis not set
#CONFIG_PREEMPT_SOFTIRQSis not set
#CONFIG_PREEMPT_HARDIRQSis not set
#CONFIG_PREEMPT_BKLis not setCONFIG_ASM_SEMAPHORES=yCONFIG_RWSEM_XCHGADD_ALGORITHM=yCONFIG_X86_UP_APIC=yCONFIG_X86_UP_IOAPIC=yCONFIG_X86_LOCAL_APIC=yCONFIG_X86_IO_APIC=yCONFIG_X86_TSC=yCONFIG_X86_MCE=y
#CONFIG_X86_MCE_NONFATALis not set
#CONFIG_X86_MCE_P4THERMALis not set
#CONFIG_TOSHIBAis not set
#CONFIG_I8Kis not set
#CONFIG_X86_REBOOTFIXUPSis not set
#CONFIG_MICROCODEis not set
#CONFIG_X86_MSRis not setCONFIG_X86_CPUID=m#
# Profiling support
#CONFIG_PROFILING=yCONFIG_OPROFILE=y#
# Kernel hacking
#CONFIG_PRINTK_TIME=yCONFIG_DEBUG_KERNEL=yCONFIG_MAGIC_SYSRQ=yCONFIG_LOG_BUF_SHIFT=15CONFIG_SCHEDSTATS=y
#CONFIG_DEBUG_SLABis not set
#CONFIG_DEBUG_SPINLOCK_SLEEPis not setCONFIG_WAKEUP_TIMING=yCONFIG_CRITICAL_IRQSOFF_TIMING=yCONFIG_CRITICAL_TIMING=yCONFIG_LATENCY_TIMING=yCONFIG_LATENCY_TRACE=yCONFIG_MCOUNT=y
#CONFIG_DEBUG_KOBJECTis not setCONFIG_DEBUG_BUGVERBOSE=y
#CONFIG_DEBUG_INFOis not set
#CONFIG_DEBUG_FSis not setCONFIG_FRAME_POINTER=yCONFIG_EARLY_PRINTK=yCONFIG_DEBUG_STACKOVERFLOW=yCONFIG_KPROBES=yCONFIG_DEBUG_STACK_USAGE=y
#CONFIG_DEBUG_PAGEALLOCis not set
#CONFIG_4KSTACKSis not setCONFIG_X86_FIND_SMP_CONFIG=yCONFIG_X86_MPPARSE=y.config with RT preemption enabled
#
# General setup
#CONFIG_LOCALVERSION=""CONFIG_SWAP=yCONFIG_SYSVIPC=yCONFIG_POSIX_MQUEUE=yCONFIG_BSD_PROCESS_ACCT=y
#CONFIG_BSD_PROCESS_ACCT_V3is not setCONFIG_SYSCTL=y
#CONFIG_AUDITis not setCONFIG_HOTPLUG=yCONFIG_KOBJECT_UEVENT=y
#CONFIG_IKCONFIGis not set
#CONFIG_EMBEDDEDis not setCONFIG_KALLSYMS=yCONFIG_KALLSYMS_ALL=y
#CONFIG_KALLSYMS_EXTRA_PASSis not setCONFIG_PRINTK=yCONFIG_BUG=yCONFIG_BASE_FULL=yCONFIG_FUTEX=yCONFIG_EPOLL=yCONFIG_SHMEM=yCONFIG_CC_ALIGN_FUNCTIONS=0CONFIG_CC_ALIGN_LABELS=0CONFIG_CC_ALIGN_LOOPS=0CONFIG_CC_ALIGN_JUMPS=0
#CONFIG_TINY_SHMEMis not setCONFIG_BASE_SMALL=0#
# Loadable module support
#CONFIG_MODULES=yCONFIG_MODULE_UNLOAD=yCONFIG_MODULE_FORCE_UNLOAD=yCONFIG_OBSOLETE_MODPARM=yCONFIG_MODVERSIONS=y
#CONFIG_MODULE_SRCVERSION_ALLis not setCONFIG_KMOD=y#
# Processor type and features
#CONFIG_X86_PC=y
#CONFIG_X86_ELANis not set
#CONFIG_X86_VOYAGERis not set
#CONFIG_X86_NUMAQis not set
#CONFIG_X86_SUMMITis not set
#CONFIG_X86_BIGSMPis not set
#CONFIG_X86_VISWSis not set
#CONFIG_X86_GENERICARCHis not set
#CONFIG_X86_ES7000is not set
#CONFIG_M386is not set
#CONFIG_M486is not set
#CONFIG_M586is not set
#CONFIG_M586TSCis not set
#CONFIG_M586MMXis not setCONFIG_M686=y
#CONFIG_MPENTIUMIIis not set
#CONFIG_MPENTIUMIIIis not set
#CONFIG_MPENTIUMMis not set
#CONFIG_MPENTIUM4is not set
#CONFIG_MK6is not set
#CONFIG_MK7is not set
#CONFIG_MK8is not set
#CONFIG_MCRUSOEis not set
#CONFIG_MEFFICEONis not set
#CONFIG_MWINCHIPC6is not set
#CONFIG_MWINCHIP2is not set
#CONFIG_MWINCHIP3Dis not set
#CONFIG_MGEODEGX1is not set
#CONFIG_MCYRIXIIIis not set
#CONFIG_MVIAC3_2is not setCONFIG_X86_GENERIC=yCONFIG_X86_CMPXCHG=yCONFIG_X86_XADD=yCONFIG_X86_L1_CACHE_SHIFT=7CONFIG_GENERIC_CALIBRATE_DELAY=yCONFIG_X86_PPRO_FENCE=yCONFIG_X86_WP_WORKS_OK=yCONFIG_X86_INVLPG=yCONFIG_X86_BSWAP=yCONFIG_X86_POPAD_OK=yCONFIG_X86_GOOD_APIC=yCONFIG_X86_INTEL_USERCOPY=yCONFIG_X86_USE_PPRO_CHECKSUM=yCONFIG_HPET_TIMER=yCONFIG_HPET_EMULATE_RTC=y
#CONFIG_SMPis not set
#CONFIG_PREEMPT_NONEis not set
#CONFIG_PREEMPT_VOLUNTARYis not set
#CONFIG_PREEMPT_DESKTOPis not setCONFIG_PREEMPT_RT=yCONFIG_PREEMPT=yCONFIG_PREEMPT_SOFTIRQS=yCONFIG_PREEMPT_HARDIRQS=yCONFIG_PREEMPT_RCU=yCONFIG_PREEMPT_BKL=yCONFIG_RWSEM_GENERIC_SPINLOCK=yCONFIG_ASM_SEMAPHORES=yCONFIG_X86_UP_APIC=yCONFIG_X86_UP_IOAPIC=yCONFIG_X86_LOCAL_APIC=yCONFIG_X86_IO_APIC=yCONFIG_X86_TSC=yCONFIG_X86_MCE=y
#CONFIG_X86_MCE_NONFATALis not set
#CONFIG_X86_MCE_P4THERMALis not set
#CONFIG_TOSHIBAis not set
#CONFIG_I8Kis not set
#CONFIG_X86_REBOOTFIXUPSis not set
#CONFIG_MICROCODEis not set
#CONFIG_X86_MSRis not setCONFIG_X86_CPUID=m#
# Profiling support
#CONFIG_PROFILING=yCONFIG_OPROFILE=y#
# Kernel hacking
#CONFIG_PRINTK_TIME=yCONFIG_DEBUG_KERNEL=yCONFIG_MAGIC_SYSRQ=yCONFIG_LOG_BUF_SHIFT=15CONFIG_SCHEDSTATS=y
#CONFIG_DEBUG_SLABis not setCONFIG_DEBUG_PREEMPT=yCONFIG_WAKEUP_TIMING=yCONFIG_PREEMPT_TRACE=yCONFIG_CRITICAL_PREEMPT_TIMING=yCONFIG_CRITICAL_IRQSOFF_TIMING=yCONFIG_CRITICAL_TIMING=yCONFIG_LATENCY_TIMING=yCONFIG_LATENCY_TRACE=yCONFIG_MCOUNT=yCONFIG_RT_DEADLOCK_DETECT=yCONFIG_DEBUG_RT_LOCKING_MODE=y
#CONFIG_DEBUG_KOBJECTis not setCONFIG_DEBUG_BUGVERBOSE=y
#CONFIG_DEBUG_INFOis not set
#CONFIG_DEBUG_FSis not setCONFIG_FRAME_POINTER=yCONFIG_EARLY_PRINTK=yCONFIG_DEBUG_STACKOVERFLOW=yCONFIG_KPROBES=yCONFIG_DEBUG_STACK_USAGE=y
#CONFIG_DEBUG_PAGEALLOCis not setCONFIG_X86_MPPARSE=yQuoted 2 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel"in
Quoted 4 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 16 lines · Milan Svoboda
Quoted 11 lines
I tried to your program: I couldn't make it fail under
PREEMPT_RT. No
matter what the termination value for the while loop in the priority 10 thread I put in the priority 50 thread printed the same "Dif:". I also put in a global variable,thread_done, which I set in the priority 10 thread after the loop and printed it out along with "Dif:". It was not set. I also tried to add exit(1) at the end of the priority 10 thread...I see no odd behaviour.
Esben
Look at my results:
I added a flag too.
Quoted 8 lines
under non RT preempt:
(these results are expected)./a.out
Flag: 0, Dif:11714
./a.out
Flag: 0, Dif:11678
(Flag:0 means the counting thread haven't finished, right?)
This is what I see on PREEMPT_RT 2.6.12-rc6-V0.7.48-04.
Quoted 9 lines
under full RT preempt:
./a.out
Flag: 1, Dif:582536
./a.out
Flag: 1, Dif:579791This shows that thread with bigger priority was
blocked by the thread with lower priority!
Yes. Odd. Tried on V0.7.48-04 ?
Esben
Quoted 8 lines · Milan Svoboda
under non RT preempt:
(these results are expected)./a.out
Flag: 0, Dif:11714
./a.out
Flag: 0, Dif:11678
Quoted 8 lines
under full RT preempt:
./a.out
Flag: 1, Dif:582536
./a.out
Flag: 1, Dif:579791This shows that thread with bigger priority was
blocked by the thread with lower priority!
Can you retry with RT-V0.7.48-05 and this patch applied?
Michal
kernel/sched.c +3 -7
@@ -1190,18 +1190,14 @@ out_activate:* this cpu. Delayed preemption is guaranteed to happen upon * return to userspace. */ -if (cpu != this_cpu) { +if (!sync || cpu != this_cpu) {activate_task (p, rq, cpu == this_cpu);if (TASK_PREEMPTS_CURR (p, rq))resched_task (rq->curr); }else {__activate_task (p, rq); -if (TASK_PREEMPTS_CURR (p, rq)) { -if (sync) -set_tsk_need_resched_delayed (rq->curr); -else -resched_task (rq->curr); - } +if (TASK_PREEMPTS_CURR (p, rq)) +set_tsk_need_resched_delayed (rq->curr); }trace_start_sched_wakeup (p, rq);if (rq->curr && p && rq &&_need_resched ())