Montag, 12. Juli 2010

linux kernel timer : dynamic ticks

linux kernel timer : dynamic ticks

quoted from : Professional Linux kernel architecture by Wolfgang Mauerer, 933-934


1. if NO active tasks are on the run queue, the kernel picks a special task-- theidle tasks to run.

2. whenever the idle task is selected to run, the periodic tick is DISABLED until the next timer will expire.

3. The tick is re-enabled again after this time span, or when an interrupt occurs.

4. In the meantime, the CPU can enjoy a well-deserved sleep.

5. Note that only classical timers need to be considered for this purpose.

High-resoultion timers are NOT bound by the tick frequency, and are aslo NOT implemented on top of periodic ticks.

6. One-shot clocks is a prerequisite for dynamic tick. The feature of a dymanic tick is that the tick mechanism can be stoped and restarted as necessary. The purely periodic timers are not suitable.

7. Periodic ticks mean a tick implementation that does NOT use dymanic ticks.

8. dynamic ticks are implemented differently on high-res and low-res timers.

9. struct tick_sched

http://lxr.linux.no/#linux+v2.6.34.1/include/linux/tick.h#L48

**
30 * struct tick_sched - sched tick emulation and no idle tick control/stats
31 * @sched_timer: hrtimer to schedule the periodic tick in high
32 * resolution mode
33 * @idle_tick: Store the last idle tick expiry time when the tick
34 * timer is modified for idle sleeps. This is necessary
35 * to resume the tick timer operation in the timeline
36 * when the CPU returns from idle
37 * @tick_stopped: Indicator that the idle tick has been stopped
38 * @idle_jiffies: jiffies at the entry to idle for idle time accounting
39 * @idle_calls: Total number of idle calls
40 * @idle_sleeps: Number of idle calls, where the sched tick was stopped
41 * @idle_entrytime: Time when the idle call was entered
42 * @idle_waketime: Time when the idle was interrupted
43 * @idle_exittime: Time when the idle state was left
44 * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped
45 * @sleep_length: Duration of the current idle sleep
46 * @do_timer_lst: CPU was the last one doing do_timer before going idle
47 */
48struct tick_sched {
49 struct hrtimer sched_timer;
50 unsigned long check_clocks;
51 enum tick_nohz_mode nohz_mode;
52 ktime_t idle_tick;
53 int inidle;
54 int tick_stopped;
55 unsigned long idle_jiffies;
56 unsigned long idle_calls;
57 unsigned long idle_sleeps;
58 int idle_active;
59 ktime_t idle_entrytime;
60 ktime_t idle_waketime;
61 ktime_t idle_exittime;
62 ktime_t idle_sleeptime;
63 ktime_t idle_lastupdate;
64 ktime_t sleep_length;
65 unsigned long last_jiffies;
66 unsigned long next_jiffies;
67 ktime_t idle_expires;
68 int do_timer_last;
69};


1 Kommentar:

Anonym hat gesagt…

香港政府有死穴

目前香港工農式微,經濟獨沽一味,以資訊流通、法治、社會安寧及高效服務吸引外人來此投資及花費。

加上此地的人口壓力早已超過臨界點,政治經濟過分集中在中環一帶,即使是消極耗損式的公民抗爭行動,只要曠日持久,也足以迫使政府屈服。

特別是八十年代中期之後,政府奉行新自由主義,實施公共服務改革,裁汰多餘,外判工作,肥上瘦下,攤薄官府權威,前線人員疲於奔命,士氣低落,掏空官僚的機動反應的剩餘精力和迴旋空間(德文的Spielraum)。

在冗員眾多而官府應急空間充沛的六七十年代,暴動應付自如,但目前香港暴動的話,醫院、機動警員、拘留所、監獄、司法檔期根本不足以應付。

當然,也可因陋就簡,快速檢控和粗暴監禁,但金融中心的聲譽勢將毀於一旦。大陸人目睹執法標準降低,也不必來香港投資定居和尋找安樂消費了。

香港不是美國,可以不假外求,香港打開大門,食的是四方飯,香港警察執法斯文,外地人也很受落。

這是大家都珍惜的香港謀生大局,然而官商勾結,小市民無立錐之地,財閥和政府也不珍惜大局的時候,小市民又有什麼必要去奉陪呢?

機會成本不對稱

過去示威者也許懼怕留下案底,難有大企業聘用,但現在人浮於事,大公司的聘用新人的條件苛刻,連中年人的老臣子也職位不保,誰會「珍惜羽毛」呢?

假若政府強橫執法,自損司法制度的道德基礎,則政治犯罪便成為人民英雄,成為「負成本」,有賺了,在社運鬧出名堂,累積經驗,反而有助拓展事業。

以機會成本而言,比起快樂示威的青年,政府和商家的機會成本高很多,根本是一場不對稱的戰爭。

政府是心知肚明的,因此要猛力壓制在萌芽狀態,以免一輸到底。政府採取各種滋擾措施來遏止示威,一退再退,卻不敢採取棍棒武力,可見政府無險可守。

抗爭當然有時要暴力要激情,特別是應付暴政。然而,港府仍非暴政,國際情勢和中共也不容港府行使暴政。

香港是中外緩衝之地,也是中共學習現代管治經驗、與國際社會接觸和挽留大陸逃逸資本之地,高效政府和溫柔政治,本來是此地最適宜的政術,只是曾蔭權不得其法,而且縱容地產財閥剝削,將港人之資財輸送予政治忠誠不明的地產商,才引起民怨沸騰,也令中共警惕。

民生問題引致的民怨,是目前抗爭的主因。政治引起的民怨,卻不緊迫。民主牽涉主權,民主政治必須要有主權意識的支持,故此中國民主的主戰場在內地,不在香港。以現實政治而言,只要港府顧全自由和均富,香港的民主足以監察政府施政和保證言論自由便夠了。


香港只須快樂抗爭,溫柔革命,保住憲政共和的開頭和完結便可,中間的部分,留待大陸同胞去做,而陣痛期間的亂局,如中美雙方協商妥當,香港也執政有術,便可以接收大陸的逃逸資本和人才,充實地方建設,成為民主中國的首善之區。