热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

内核中的jiffies变量

关于内核中的jiffies变量,可通过下图解释。在内核中很多函数的参数都是都是以jiffies为单位的,如定时器中mod_timer(&timer,ji

关于内核中的jiffies变量,可通过下图解释。

在内核中很多函数的参数都是都是以jiffies为单位的,如定时器中mod_timer(&timer, jiffies + 2*HZ);

jiffies代表当前发生中断的次数,2*Hz代表发生了发生了2*Hz次中断,那jiffies+2Hz就是未来时间点的中断次数,转换成时间就是2s后的时间点。

还有很多表示时间的用jiffies为单位的函数,如

 

/*** mod_timer - modify a timer's timeout* @timer: the timer to be modified* @expires: new timeout in jiffies** mod_timer() is a more efficient way to update the expire field of an* active timer (if the timer is inactive it will be activated)** mod_timer(timer, expires) is equivalent to:** del_timer(timer); timer->expires = expires; add_timer(timer);** Note that if there are multiple unserialized concurrent users of the* same timer, then mod_timer() is the only safe way to modify the timeout,* since add_timer() cannot modify an already running timer.** The function returns whether it has modified a pending timer or not.* (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an* active timer returns 1.)*/
int mod_timer(struct timer_list *timer, unsigned long expires)
{expires = apply_slack(timer, expires);/** This is a common optimization triggered by the* networking code - if the timer is re-modified* to be the same thing then just return:*/if (timer_pending(timer) && timer->expires == expires)return 1;return __mod_timer(timer, expires, false, TIMER_NOT_PINNED);
}
EXPORT_SYMBOL(mod_timer);

 

/*** wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses* @wq: the waitqueue to wait on* @condition: a C expression for the event to wait for* @timeout: timeout, in jiffies** The process is put to sleep (TASK_INTERRUPTIBLE) until the* @condition evaluates to true or a signal is received.* The @condition is checked each time the waitqueue @wq is woken up.** wake_up() has to be called after changing any variable that could* change the result of the wait condition.** Returns:* 0 if the @timeout elapsed, -%ERESTARTSYS if it was interrupted by* a signal, or the remaining jiffies (at least 1) if the @condition* evaluated to %true before the @timeout elapsed.*/
#define wait_event_interruptible_timeout(wq, condition, timeout) \
({ \long __ret = timeout; \if (!___wait_cond_timeout(condition)) \__ret = __wait_event_interruptible_timeout(wq, \condition, timeout); \__ret; \
})

 

/*** schedule_delayed_work - put work task in global workqueue after delay* @dwork: job to be done* @delay: number of jiffies to wait or 0 for immediate execution** After waiting for a given time this puts a job in the kernel-global* workqueue.*/
static inline bool schedule_delayed_work(struct delayed_work *dwork,unsigned long delay)

当然,也有相应的函数将我们常用的时间如ms转化成jiffies的,如msecs_to_jiffies

unsigned long msecs_to_jiffies(const unsigned int m)
{/** Negative value, means infinite timeout:*/if ((int)m <0)return MAX_JIFFY_OFFSET;#if HZ <&#61; MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)/** HZ is equal to or smaller than 1000, and 1000 is a nice* round multiple of HZ, divide with the factor between them,* but round upwards:*/return (m &#43; (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)/** HZ is larger than 1000, and HZ is a nice round multiple of* 1000 - simply multiply with the factor between them.** But first make sure the multiplication result cannot* overflow:*/if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))return MAX_JIFFY_OFFSET;return m * (HZ / MSEC_PER_SEC);
#else/** Generic case - multiply, round and divide. But first* check that if we are doing a net multiplication, that* we wouldn&#39;t overflow:*/if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))return MAX_JIFFY_OFFSET;return (MSEC_TO_HZ_MUL32 * m &#43; MSEC_TO_HZ_ADJ32)>> MSEC_TO_HZ_SHR32;
#endif
}
EXPORT_SYMBOL(msecs_to_jiffies);

 

 

 

 

 


推荐阅读
  • 前言--页数多了以后需要指定到某一页(只做了功能,样式没有细调)html ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • This request pertains to exporting the hosted_zone_id attribute associated with the aws_rds_cluster resource in Terraform configurations. The absence of this attribute can lead to issues when integrating DNS records with Route 53. ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 本文基于刘洪波老师的《英文词根词缀精讲》,深入探讨了多个重要词根词缀的起源及其相关词汇,帮助读者更好地理解和记忆英语单词。 ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • Android 渐变圆环加载控件实现
    本文介绍了如何在 Android 中创建一个自定义的渐变圆环加载控件,该控件已在多个知名应用中使用。我们将详细探讨其工作原理和实现方法。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 作为一名 Ember.js 新手,了解如何在路由和模型中正确加载 JSON 数据是至关重要的。本文将探讨两者之间的差异,并提供实用的建议。 ... [详细]
  • JavaScript 基础语法指南
    本文详细介绍了 JavaScript 的基础语法,包括变量、数据类型、运算符、语句和函数等内容,旨在为初学者提供全面的入门指导。 ... [详细]
author-avatar
乐橙味_367
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有