⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiffies.h

📁 Axis 221 camera embedded programing interface
💻 H
📖 第 1 页 / 共 2 页
字号:
#define NSEC_CONVERSION ((unsigned long)((((u64)1 << NSEC_JIFFIE_SC) +\                                        TICK_NSEC -1) / (u64)TICK_NSEC))#define USEC_CONVERSION  \                    ((unsigned long)((((u64)NSEC_PER_USEC << USEC_JIFFIE_SC) +\                                        TICK_NSEC -1) / (u64)TICK_NSEC))/* * USEC_ROUND is used in the timeval to jiffie conversion.  See there * for more details.  It is the scaled resolution rounding value.  Note * that it is a 64-bit value.  Since, when it is applied, we are already * in jiffies (albit scaled), it is nothing but the bits we will shift * off. */#define USEC_ROUND (u64)(((u64)1 << USEC_JIFFIE_SC) - 1)/* * The maximum jiffie value is (MAX_INT >> 1).  Here we translate that * into seconds.  The 64-bit case will overflow if we are not careful, * so use the messy SH_DIV macro to do it.  Still all constants. */#if BITS_PER_LONG < 64# define MAX_SEC_IN_JIFFIES \	(long)((u64)((u64)MAX_JIFFY_OFFSET * TICK_NSEC) / NSEC_PER_SEC)#else	/* take care of overflow on 64 bits machines */# define MAX_SEC_IN_JIFFIES \	(SH_DIV((MAX_JIFFY_OFFSET >> SEC_JIFFIE_SC) * TICK_NSEC, NSEC_PER_SEC, 1) - 1)#endif/* * Convert jiffies to milliseconds and back. * * Avoid unnecessary multiplications/divisions in the * two most common HZ cases: */static inline unsigned int jiffies_to_msecs(const unsigned long j){#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)	return (MSEC_PER_SEC / HZ) * j;#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)	return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);#else	return (j * MSEC_PER_SEC) / HZ;#endif}static inline unsigned int jiffies_to_usecs(const unsigned long j){#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)	return (USEC_PER_SEC / HZ) * j;#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)	return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);#else	return (j * USEC_PER_SEC) / HZ;#endif}static inline unsigned long msecs_to_jiffies(const unsigned int m){	if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))		return MAX_JIFFY_OFFSET;#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)	return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)	return m * (HZ / MSEC_PER_SEC);#else	return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;#endif}static inline unsigned long usecs_to_jiffies(const unsigned int u){	if (u > jiffies_to_usecs(MAX_JIFFY_OFFSET))		return MAX_JIFFY_OFFSET;#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)	return (u + (USEC_PER_SEC / HZ) - 1) / (USEC_PER_SEC / HZ);#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)	return u * (HZ / USEC_PER_SEC);#else	return (u * HZ + USEC_PER_SEC - 1) / USEC_PER_SEC;#endif}/* * The TICK_NSEC - 1 rounds up the value to the next resolution.  Note * that a remainder subtract here would not do the right thing as the * resolution values don't fall on second boundries.  I.e. the line: * nsec -= nsec % TICK_NSEC; is NOT a correct resolution rounding. * * Rather, we just shift the bits off the right. * * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec * value to a scaled second value. */static __inline__ unsigned longtimespec_to_jiffies(const struct timespec *value){	unsigned long sec = value->tv_sec;	long nsec = value->tv_nsec + TICK_NSEC - 1;	if (sec >= MAX_SEC_IN_JIFFIES){		sec = MAX_SEC_IN_JIFFIES;		nsec = 0;	}	return (((u64)sec * SEC_CONVERSION) +		(((u64)nsec * NSEC_CONVERSION) >>		 (NSEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;}static __inline__ voidjiffies_to_timespec(const unsigned long jiffies, struct timespec *value){	/*	 * Convert jiffies to nanoseconds and separate with	 * one divide.	 */	u64 nsec = (u64)jiffies * TICK_NSEC;	value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_nsec);}/* Same for "timeval" * * Well, almost.  The problem here is that the real system resolution is * in nanoseconds and the value being converted is in micro seconds. * Also for some machines (those that use HZ = 1024, in-particular), * there is a LARGE error in the tick size in microseconds. * The solution we use is to do the rounding AFTER we convert the * microsecond part.  Thus the USEC_ROUND, the bits to be shifted off. * Instruction wise, this should cost only an additional add with carry * instruction above the way it was done above. */static __inline__ unsigned longtimeval_to_jiffies(const struct timeval *value){	unsigned long sec = value->tv_sec;	long usec = value->tv_usec;	if (sec >= MAX_SEC_IN_JIFFIES){		sec = MAX_SEC_IN_JIFFIES;		usec = 0;	}	return (((u64)sec * SEC_CONVERSION) +		(((u64)usec * USEC_CONVERSION + USEC_ROUND) >>		 (USEC_JIFFIE_SC - SEC_JIFFIE_SC))) >> SEC_JIFFIE_SC;}static __inline__ voidjiffies_to_timeval(const unsigned long jiffies, struct timeval *value){	/*	 * Convert jiffies to nanoseconds and separate with	 * one divide.	 */	u64 nsec = (u64)jiffies * TICK_NSEC;	long tv_usec;	value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec);	tv_usec /= NSEC_PER_USEC;	value->tv_usec = tv_usec;}/* * Convert jiffies/jiffies_64 to clock_t and back. */static inline clock_t jiffies_to_clock_t(long x){#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0	return x / (HZ / USER_HZ);#else	u64 tmp = (u64)x * TICK_NSEC;	do_div(tmp, (NSEC_PER_SEC / USER_HZ));	return (long)tmp;#endif}static inline unsigned long clock_t_to_jiffies(unsigned long x){#if (HZ % USER_HZ)==0	if (x >= ~0UL / (HZ / USER_HZ))		return ~0UL;	return x * (HZ / USER_HZ);#else	u64 jif;	/* Don't worry about loss of precision here .. */	if (x >= ~0UL / HZ * USER_HZ)		return ~0UL;	/* .. but do try to contain it here */	jif = x * (u64) HZ;	do_div(jif, USER_HZ);	return jif;#endif}static inline u64 jiffies_64_to_clock_t(u64 x){#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0	do_div(x, HZ / USER_HZ);#else	/*	 * There are better ways that don't overflow early,	 * but even this doesn't overflow in hundreds of years	 * in 64 bits, so..	 */	x *= TICK_NSEC;	do_div(x, (NSEC_PER_SEC / USER_HZ));#endif	return x;}static inline u64 nsec_to_clock_t(u64 x){#if (NSEC_PER_SEC % USER_HZ) == 0	do_div(x, (NSEC_PER_SEC / USER_HZ));#elif (USER_HZ % 512) == 0	x *= USER_HZ/512;	do_div(x, (NSEC_PER_SEC / 512));#else	/*         * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,         * overflow after 64.99 years.         * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...         */	x *= 9;	do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (USER_HZ/2))	                          / USER_HZ));#endif	return x;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -