include/linux/dynamic_queue_limits.h

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

File Facts

System
Linux kernel
Corpus path
include/linux/dynamic_queue_limits.h
Extension
.h
Size
5562 bytes
Lines
164
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

struct dql {
	/* Fields accessed in enqueue path (dql_queued) */
	unsigned int	num_queued;		/* Total ever queued */
	unsigned int	adj_limit;		/* limit + num_completed */
	unsigned int	last_obj_cnt;		/* Count at last queuing */

	/* Stall threshold (in jiffies), defined by user */
	unsigned short	stall_thrs;

	unsigned long	history_head;		/* top 58 bits of jiffies */
	/* stall entries, a bit per entry */
	unsigned long	history[DQL_HIST_LEN];

	/* Fields accessed only by completion path (dql_completed) */

	unsigned int	limit ____cacheline_aligned_in_smp; /* Current limit */
	unsigned int	num_completed;		/* Total ever completed */

	unsigned int	prev_ovlimit;		/* Previous over limit */
	unsigned int	prev_num_queued;	/* Previous queue total */
	unsigned int	prev_last_obj_cnt;	/* Previous queuing cnt */

	unsigned int	lowest_slack;		/* Lowest slack found */
	unsigned long	slack_start_time;	/* Time slacks seen */

	/* Configuration */
	unsigned int	max_limit;		/* Max limit */
	unsigned int	min_limit;		/* Minimum limit */
	unsigned int	slack_hold_time;	/* Time to measure slack */

	/* Longest stall detected, reported to user */
	unsigned short	stall_max;
	unsigned long	last_reap;		/* Last reap (in jiffies) */
	unsigned long	stall_cnt;		/* Number of stalls */
};

/* Set some static maximums */
#define DQL_MAX_OBJECT (UINT_MAX / 16)
#define DQL_MAX_LIMIT ((UINT_MAX / 2) - DQL_MAX_OBJECT)

/* Populate the bitmap to be processed later in dql_check_stall() */
static inline void dql_queue_stall(struct dql *dql)
{
	unsigned long map, now, now_hi, i;

	now = jiffies;
	now_hi = now / BITS_PER_LONG;

	/* The following code set a bit in the ring buffer, where each
	 * bit trackes time the packet was queued. The dql->history buffer
	 * tracks DQL_HIST_LEN * BITS_PER_LONG time (jiffies) slot
	 */
	if (unlikely(now_hi != dql->history_head)) {
		/* About to reuse slots, clear them */
		for (i = 0; i < DQL_HIST_LEN; i++) {
			/* Multiplication masks high bits */
			if (now_hi * BITS_PER_LONG ==
			    (dql->history_head + i) * BITS_PER_LONG)
				break;
			DQL_HIST_ENT(dql, dql->history_head + i + 1) = 0;
		}
		/* pairs with smp_rmb() in dql_check_stall() */
		smp_wmb();
		WRITE_ONCE(dql->history_head, now_hi);
	}

	/* __set_bit() does not guarantee WRITE_ONCE() semantics */
	map = DQL_HIST_ENT(dql, now_hi);

	/* Populate the history with an entry (bit) per queued */
	if (!(map & BIT_MASK(now)))
		WRITE_ONCE(DQL_HIST_ENT(dql, now_hi), map | BIT_MASK(now));
}

/*
 * Record number of objects queued. Assumes that caller has already checked
 * availability in the queue with dql_avail.
 */
static inline void dql_queued(struct dql *dql, unsigned int count)
{
	if (WARN_ON_ONCE(count > DQL_MAX_OBJECT))
		return;

	WRITE_ONCE(dql->last_obj_cnt, count);

	/* We want to force a write first, so that cpu do not attempt
	 * to get cache line containing last_obj_cnt, num_queued, adj_limit
	 * in Shared state, but directly does a Request For Ownership
	 * It is only a hint, we use barrier() only.
	 */

Annotation

Implementation Notes