<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 7.7.?快速參考 本章介紹了下面的符號. ### 7.7.1.?時間管理 ~~~ #include <linux/param.h> HZ ~~~ HZ 符號指定了每秒產生的時鐘嘀噠的數目. ~~~ #include <linux/jiffies.h> volatile unsigned long jiffies; u64 jiffies_64; ~~~ jiffies_64 變量每個時鐘嘀噠時被遞增; 因此, 它是每秒遞增 HZ 次. 內核代碼幾乎常常引用 jiffies, 它在 64-位平臺和 jiffies_64 相同并且在 32-位平臺是它低有效的一半. ~~~ int time_after(unsigned long a, unsigned long b); int time_before(unsigned long a, unsigned long b); int time_after_eq(unsigned long a, unsigned long b); int time_before_eq(unsigned long a, unsigned long b); ~~~ 這些布爾表達式以一種安全的方式比較 jiffies, 沒有萬一計數器溢出的問題和不需要存取 jiffies_64. ~~~ u64 get_jiffies_64(void); ~~~ 獲取 jiffies_64 而沒有競爭條件. ~~~ #include <linux/time.h> unsigned long timespec_to_jiffies(struct timespec *value); void jiffies_to_timespec(unsigned long jiffies, struct timespec *value); unsigned long timeval_to_jiffies(struct timeval *value); void jiffies_to_timeval(unsigned long jiffies, struct timeval *value); ~~~ 在 jiffies 和其他表示之間轉換時間表示. ~~~ #include <asm/msr.h> rdtsc(low32,high32); rdtscl(low32); rdtscll(var32); ~~~ x86-特定的宏定義來讀取時戳計數器. 它們作為 2 半 32-位來讀取, 只讀低一半, 或者全部讀到一個 long long 變量. ~~~ #include <linux/timex.h> cycles_t get_cycles(void); ~~~ 以平臺獨立的方式返回時戳計數器. 如果 CPU 沒提供時戳特性, 返回 0. ~~~ #include <linux/time.h> unsigned long mktime(year, mon, day, h, m, s); ~~~ 返回自 Epoch 以來的秒數, 基于 6 個 unsigned int 參數. ~~~ void do_gettimeofday(struct timeval *tv); ~~~ 返回當前時間, 作為自 Epoch 以來的秒數和微秒數, 用硬件能提供的最好的精度. 在大部分的平臺這個解決方法是一個微秒或者更好, 盡管一些平臺只提供 jiffies 精度. ~~~ struct timespec current_kernel_time(void); ~~~ 返回當前時間, 以一個 jiffy 的精度. ### 7.7.2.?延遲 ~~~ #include <linux/wait.h> long wait_event_interruptible_timeout(wait_queue_head_t *q, condition, signed long timeout); ~~~ 使當前進程在等待隊列進入睡眠, 安裝一個以 jiffies 表達的超時值. 使用 schedule_timeout( 下面) 給不可中斷睡眠. ~~~ #include <linux/sched.h> signed long schedule_timeout(signed long timeout); ~~~ 調用調度器, 在確保當前進程在超時到的時候被喚醒后. 調用者首先必須調用 set_curret_state 來使自己進入一個可中斷的或者不可中斷的睡眠狀態. ~~~ #include <linux/delay.h> void ndelay(unsigned long nsecs); void udelay(unsigned long usecs); void mdelay(unsigned long msecs); ~~~ 引入一個整數納秒, 微秒和毫秒的延遲. 獲得的延遲至少是請求的值, 但是可能更多. 每個函數的參數必須不超過一個平臺特定的限制(常常是幾千). ~~~ void msleep(unsigned int millisecs); unsigned long msleep_interruptible(unsigned int millisecs); void ssleep(unsigned int seconds); ~~~ 使進程進入睡眠給定的毫秒數(或者秒, 如果使 ssleep). ### 7.7.3.?內核定時器 ~~~ #include <asm/hardirq.h> int in_interrupt(void); int in_atomic(void); ~~~ 返回一個布爾值告知是否調用代碼在中斷上下文或者原子上下文執行. 中斷上下文是在一個進程上下文之外, 或者在硬件或者軟件中斷處理中. 原子上下文是當你不能調度一個中斷上下文或者一個持有一個自旋鎖的進程的上下文. ~~~ #include <linux/timer.h> void init_timer(struct timer_list * timer); struct timer_list TIMER_INITIALIZER(_function, _expires, _data); ~~~ 這個函數和靜態的定時器結構的聲明是初始化一個 timer_list 數據結構的 2 個方法. ~~~ void add_timer(struct timer_list * timer); ~~~ 注冊定時器結構來在當前 CPU 上運行. ~~~ int mod_timer(struct timer_list *timer, unsigned long expires); ~~~ 改變一個已經被調度的定時器結構的超時時間. 它也能作為一個 add_timer 的替代. ~~~ int timer_pending(struct timer_list * timer); ~~~ 宏定義, 返回一個布爾值說明是否這個定時器結構已經被注冊運行. ~~~ void del_timer(struct timer_list * timer); void del_timer_sync(struct timer_list * timer); ~~~ 從激活的定時器鏈表中去除一個定時器. 后者保證這定時器當前沒有在另一個 CPU 上運行. ### 7.7.4.?Tasklets 機制 ~~~ #include <linux/interrupt.h> DECLARE_TASKLET(name, func, data); DECLARE_TASKLET_DISABLED(name, func, data); void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data); ~~~ 前 2 個宏定義聲明一個 tasklet 結構, 而 tasklet_init 函數初始化一個已經通過分配或其他方式獲得的 tasklet 結構. 第 2 個 DECLARE 宏標識這個 tasklet 為禁止的. ~~~ void tasklet_disable(struct tasklet_struct *t); void tasklet_disable_nosync(struct tasklet_struct *t); void tasklet_enable(struct tasklet_struct *t); ~~~ 禁止和使能一個 tasklet. 每個禁止必須配對一個使能( 你可以禁止這個 tasklet 即便它已經被禁止). 函數 tasklet_disable 等待 tasklet 終止如果它在另一個 CPU 上運行. 這個非同步版本不采用這個額外的步驟. ~~~ void tasklet_schedule(struct tasklet_struct *t); void tasklet_hi_schedule(struct tasklet_struct *t); ~~~ 調度一個 tasklet 運行, 或者作為一個"正常" tasklet 或者一個高優先級的. 當軟中斷被執行, 高優先級 tasklets 被首先處理, 而正常 tasklet 最后執行. ~~~ void tasklet_kill(struct tasklet_struct *t); ~~~ 從激活的鏈表中去掉 tasklet, 如果它被調度執行. 如同 tasklet_disable, 這個函數可能在 SMP 系統中阻塞等待 tasklet 終止, 如果它當前在另一個 CPU 上運行. ### 7.7.5.?工作隊列 ~~~ #include <linux/workqueue.h> struct workqueue_struct; struct work_struct; ~~~ 這些結構分別表示一個工作隊列和一個工作入口. ~~~ struct workqueue_struct *create_workqueue(const char *name); struct workqueue_struct *create_singlethread_workqueue(const char *name); void destroy_workqueue(struct workqueue_struct *queue); ~~~ 創建和銷毀工作隊列的函數. 一個對 create_workqueue 的調用創建一個有一個工作者線程在系統中每個處理器上的隊列; 相反, create_singlethread_workqueue 創建一個有一個單個工作者進程的工作隊列. ~~~ DECLARE_WORK(name, void (*function)(void *), void *data); INIT_WORK(struct work_struct *work, void (*function)(void *), void *data); PREPARE_WORK(struct work_struct *work, void (*function)(void *), void *data); ~~~ 聲明和初始化工作隊列入口的宏. int queue_work(struct workqueue_struct *queue, struct work_struct *work);int queue_delayed_work(struct workqueue_struct *queue, struct work_struct *work, unsigned long delay); 從一個工作隊列對工作進行排隊執行的函數. ~~~ int cancel_delayed_work(struct work_struct *work); void flush_workqueue(struct workqueue_struct *queue); ~~~ 使用 cancel_delayed_work 來從一個工作隊列中去除入口; flush_workqueue 確保沒有工作隊列入口在系統中任何地方運行. ~~~ int schedule_work(struct work_struct *work); int schedule_delayed_work(struct work_struct *work, unsigned long delay); void flush_scheduled_work(void); ~~~ 使用共享隊列的函數.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看