jiffies The total number of beats that have been generated since the system started. externUnsignedLong volatilejiffies;externU64 jiffies_64; Comparison of several macros of time: Time_after (unknown, known)//unknown after known? True:false;Time_before (unknown, known)//unknown before known True:false;Time_after_eq (unknown, known)//unknown after or eq known? true:false;Time_before_eq (unknown, known)//unknown before or eq known? true:false;where the unknown parameter is usually the Jiffies,known parameter is a value that needs to be compared. Beat rate for kernel space use: Hz user space using the beat rate: user_hzjiffies_to_clock_t ()//converts a count of ticks expressed in Hz to a beat count represented by User_hzjiffies_64_to_clock_t ()//converts the units of a 64-bit jiffies value from HZ to User_hzSecond, timer (dynamic timer, core timer)structtimer_list My_timer;init_timer (&my_timer);//Initialize the internal value of the timer data structureMy_timer.expires= jiffies + delay;//set the number of Beats when the timer times outMy_timer.data =0;//set parameters for timer handler functionsMy_timer.function = my_function;//Set Timer Timeout handler functionfunction prototypes for timer processing functions:voidMy_timer_function (unsignedLongdata); Add_timer (&my_timer);//Activating the timerMod_timer (&my_timer, jiffies + new_dalay);//changing the time-out period for a specified timer//If the timer is not activated, Mod_timer activates the timer//If the timer is not activated at the time of the call, the function returns 0; otherwise 1 is returned.Del_timer (&my_timer);//Stop the timer before the timer times out//The function can be used by a timer that is activated or not activated//If the timer is not activated at the time of the call, the function returns 0; otherwise 1 is returned. //you do not need to call this function for timers that have timed out, because they will automatically deleteDel_timer_sync (&my_timer);//wait for the timer handler that may be running on the other processor to exit after the timer is removed. Note: the Del_timer_sync () function cannot be used in the context of an interrupt. Note: The following code is not allowed: Del_timer (&my_timer); My_timer.expires= Jiffies +New_delay;add_timer (&my_timer); substitution function: Mod_timer (&my_timer, Jiffies +new_dalay); otherwise it is not secure on multiprocessor machines. Iii. deferred execution note: Deferred execution should not occur at the time of holding the lock or when the interrupt is disabled, in either case. 1. Busy waiting for unsignedLongTimeout = jiffies +Ten; while(Time_before (jiffies, timeout)); //The delay time is an integral multiple of the beat and the accuracy is not high .unsignedLongDelay = jiffies +5*HZ; while(Time_before (jiffies, delay)) cond_resched (); //the cond_resched () function dispatches a new program to run, but it only takes effect when the need_resched flag is set.//In other words, the effective condition of this method is that there are more important tasks in the system that need to be run. //it cannot be used in an interrupt context, only in the context of a process. 2. Short delayvoidUdelay (unsignedLongusecs)voidNdelay (unsignedLongnsecs)voidMdelay (unsignedLongmsecs)3. Schedule_timeout () set_current_state (state); //set a task as either an interruptible or non-interruptible sleep stateSchedule_timeout (s*hz);//wake after S seconds//when the specified time expires, the kernel wakes up the deferred task and re-puts it back into the run queue. Note: You must first set the task to one of the above two states before calling the Schedule_timeout () function, or the task will not sleep. The calling code must be in the context of the process and cannot hold the lock. 4. Set the time-out to sleep on the waiting queue. Conditions of use: Waiting for a task on a queue might be waiting for a specific event to arrive and waiting for a specific time to expire--see who comes faster.
Timer and Time management