include/linux/units.h

Source file repositories/reference/linux-study-clean/include/linux/units.h

File Facts

System
Linux kernel
Corpus path
include/linux/units.h
Extension
.h
Size
3709 bytes
Lines
145
Domain
Core OS
Bucket
Core Kernel Interface
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

#ifndef _LINUX_UNITS_H
#define _LINUX_UNITS_H

#include <linux/bits.h>
#include <linux/math.h>

/* Metric prefixes in accordance with Système international (d'unités) */
#define PETA	1000000000000000ULL
#define TERA	1000000000000ULL
#define GIGA	1000000000UL
#define MEGA	1000000UL
#define KILO	1000UL
#define HECTO	100UL
#define DECA	10UL
#define DECI	10UL
#define CENTI	100UL
#define MILLI	1000UL
#define MICRO	1000000UL
#define NANO	1000000000UL
#define PICO	1000000000000ULL
#define FEMTO	1000000000000000ULL

/*
 * Percentage and related scaling units
 *
 * These macros define scaling factors used to convert between ratio and
 * percentage-based representations with different decimal resolutions.
 * They are used for precise fractional calculations in engineering, finance,
 * and measurement applications.
 *
 * Examples:
 *   1%     = 0.01    = 1 / PERCENT
 *   0.1%   = 0.001   = 1 / PERMILLE
 *   0.01%  = 0.0001  = 1 / PERMYRIAD (1 basis point)
 *   0.001% = 0.00001 = 1 / PERCENTMILLE
 */
#define PERCENT		100
#define PERMILLE	1000
#define PERMYRIAD	10000
#define PERCENTMILLE	100000

#define NANOHZ_PER_HZ		1000000000UL
#define MICROHZ_PER_HZ		1000000UL
#define MILLIHZ_PER_HZ		1000UL

/* Hz based multipliers */
#define HZ_PER_KHZ		1000UL
#define HZ_PER_MHZ		1000000UL
#define HZ_PER_GHZ		1000000000UL

/* kHz based multipliers */
#define KHZ_PER_MHZ		1000UL
#define KHZ_PER_GHZ		1000000UL

#define MILLIWATT_PER_WATT	1000UL
#define MICROWATT_PER_MILLIWATT	1000UL
#define MICROWATT_PER_WATT	1000000UL

#define MICROJOULE_PER_JOULE	1000000UL
#define NANOJOULE_PER_JOULE	1000000000UL

#define BYTES_PER_KBIT		(KILO / BITS_PER_BYTE)
#define BYTES_PER_MBIT		(MEGA / BITS_PER_BYTE)
#define BYTES_PER_GBIT		(GIGA / BITS_PER_BYTE)

#define ABSOLUTE_ZERO_MILLICELSIUS -273150

static inline long milli_kelvin_to_millicelsius(long t)
{
	return t + ABSOLUTE_ZERO_MILLICELSIUS;
}

static inline long millicelsius_to_milli_kelvin(long t)
{
	return t - ABSOLUTE_ZERO_MILLICELSIUS;
}

#define MILLIDEGREE_PER_DEGREE 1000
#define MILLIDEGREE_PER_DECIDEGREE 100

static inline long kelvin_to_millicelsius(long t)
{
	return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DEGREE);
}

static inline long millicelsius_to_kelvin(long t)
{
	t = millicelsius_to_milli_kelvin(t);

	return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE);

Annotation

Implementation Notes