Project

General

Profile

Bug #15438 ยป 0001-dynamically-modify-the-timer-thread-period-to-accoun.patch

sylvain.joyeux (Sylvain Joyeux), 12/20/2018 01:23 PM

View differences:

thread.c
76 76
#ifndef USE_NATIVE_THREAD_PRIORITY
77 77
#define USE_NATIVE_THREAD_PRIORITY 0
78 78
#define RUBY_THREAD_PRIORITY_MAX 3
79
#define RUBY_THREAD_PRIORITY_MIN -3
79
#define RUBY_THREAD_PRIORITY_MIN -5
80 80
#endif
81 81

  
82 82
#ifndef THREAD_DEBUG
......
1778 1778
    return ST_CONTINUE;
1779 1779
}
1780 1780

  
1781
static int
1782
thread_time_quantum_usec_from_priority(int priority) {
1783
    if (priority > 0) {
1784
        return TIME_QUANTUM_USEC_BASE << priority;
1785
    }
1786
    else {
1787
        return TIME_QUANTUM_USEC_BASE >> -priority;
1788
    }
1789
}
1790

  
1791

  
1781 1792
/*
1782 1793
 * call-seq:
1783 1794
 *   Thread.handle_interrupt(hash) { ... } -> result of the block
......
2117 2128
	}
2118 2129

  
2119 2130
	if (timer_interrupt) {
2120
	    uint32_t limits_us = TIME_QUANTUM_USEC;
2121

  
2122
	    if (th->priority > 0)
2123
		limits_us <<= th->priority;
2124
	    else
2125
		limits_us >>= -th->priority;
2131
	    uint32_t limits_us = thread_time_quantum_usec_from_priority(th->priority);
2126 2132

  
2127 2133
	    if (th->status == THREAD_RUNNABLE)
2128 2134
		th->running_time_us += TIME_QUANTUM_USEC;
......
3483 3489
{
3484 3490
    rb_thread_t *target_th = rb_thread_ptr(thread);
3485 3491
    int priority;
3492
    int new_quantum_usec;
3486 3493

  
3487 3494
#if USE_NATIVE_THREAD_PRIORITY
3488 3495
    target_th->priority = NUM2INT(prio);
......
3495 3502
    else if (priority < RUBY_THREAD_PRIORITY_MIN) {
3496 3503
	priority = RUBY_THREAD_PRIORITY_MIN;
3497 3504
    }
3505

  
3506
    new_quantum_usec = thread_time_quantum_usec_from_priority(priority);
3507
    if (TIME_QUANTUM_USEC > new_quantum_usec)
3508
        TIME_QUANTUM_USEC = new_quantum_usec;
3498 3509
    target_th->priority = priority;
3499 3510
#endif
3500 3511
    return INT2NUM(target_th->priority);
thread_pthread.c
1246 1246
/* 100ms.  10ms is too small for user level thread scheduling
1247 1247
 * on recent Linux (tested on 2.6.35)
1248 1248
 */
1249
#define TIME_QUANTUM_USEC (100 * 1000)
1249
#define TIME_QUANTUM_USEC_BASE (100 * 1000)
1250
static int TIME_QUANTUM_USEC = TIME_QUANTUM_USEC_BASE;
1250 1251

  
1251 1252
#if USE_SLEEPY_TIMER_THREAD
1252 1253
static struct {
thread_win32.c
13 13

  
14 14
#include <process.h>
15 15

  
16
#define TIME_QUANTUM_USEC (10 * 1000)
16
#define TIME_QUANTUM_USEC_BASE (10 * 1000)
17
static int TIME_QUANTUM_USEC = TIME_QUANTUM_USEC_BASE;
17 18
#define RB_CONDATTR_CLOCK_MONOTONIC 1 /* no effect */
18 19

  
19 20
#undef Sleep
20
-