lib/dynamic_queue_limits.c
Source file repositories/reference/linux-study-clean/lib/dynamic_queue_limits.c
File Facts
- System
- Linux kernel
- Corpus path
lib/dynamic_queue_limits.c- Extension
.c- Size
- 6782 bytes
- Lines
- 218
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hlinux/kernel.hlinux/jiffies.hlinux/dynamic_queue_limits.hlinux/compiler.hlinux/export.htrace/events/napi.h
Detected Declarations
function Copyrightfunction dql_completedfunction dql_resetfunction dql_initexport dql_completedexport dql_resetexport dql_init
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Dynamic byte queue limits. See include/linux/dynamic_queue_limits.h
*
* Copyright (c) 2011, Tom Herbert <therbert@google.com>
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/jiffies.h>
#include <linux/dynamic_queue_limits.h>
#include <linux/compiler.h>
#include <linux/export.h>
#include <trace/events/napi.h>
#define POSDIFF(A, B) ((int)((A) - (B)) > 0 ? (A) - (B) : 0)
#define AFTER_EQ(A, B) ((int)((A) - (B)) >= 0)
static void dql_check_stall(struct dql *dql, unsigned short stall_thrs)
{
unsigned long now;
if (!stall_thrs)
return;
now = jiffies;
/* Check for a potential stall */
if (time_after_eq(now, dql->last_reap + stall_thrs)) {
unsigned long hist_head, t, start, end;
/* We are trying to detect a period of at least @stall_thrs
* jiffies without any Tx completions, but during first half
* of which some Tx was posted.
*/
dqs_again:
hist_head = READ_ONCE(dql->history_head);
/* pairs with smp_wmb() in dql_queued() */
smp_rmb();
/* Get the previous entry in the ring buffer, which is the
* oldest sample.
*/
start = (hist_head - DQL_HIST_LEN + 1) * BITS_PER_LONG;
/* Advance start to continue from the last reap time */
if (time_before(start, dql->last_reap + 1))
start = dql->last_reap + 1;
/* Newest sample we should have already seen a completion for */
end = hist_head * BITS_PER_LONG + (BITS_PER_LONG - 1);
/* Shrink the search space to [start, (now - start_thrs/2)] if
* `end` is beyond the stall zone
*/
if (time_before(now, end + stall_thrs / 2))
end = now - stall_thrs / 2;
/* Search for the queued time in [t, end] */
for (t = start; time_before_eq(t, end); t++)
if (test_bit(t % (DQL_HIST_LEN * BITS_PER_LONG),
dql->history))
break;
/* Variable t contains the time of the queue */
if (!time_before_eq(t, end))
goto no_stall;
/* The ring buffer was modified in the meantime, retry */
if (hist_head != READ_ONCE(dql->history_head))
goto dqs_again;
dql->stall_cnt++;
dql->stall_max = max_t(unsigned short, dql->stall_max, now - t);
trace_dql_stall_detected(dql->stall_thrs, now - t,
dql->last_reap, dql->history_head,
now, dql->history);
}
no_stall:
dql->last_reap = now;
}
/* Records completed count and recalculates the queue limit */
void dql_completed(struct dql *dql, unsigned int count)
{
unsigned int inprogress, prev_inprogress, limit;
unsigned int ovlimit, completed, num_queued;
unsigned short stall_thrs;
bool all_prev_completed;
num_queued = READ_ONCE(dql->num_queued);
Annotation
- Immediate include surface: `linux/types.h`, `linux/kernel.h`, `linux/jiffies.h`, `linux/dynamic_queue_limits.h`, `linux/compiler.h`, `linux/export.h`, `trace/events/napi.h`.
- Detected declarations: `function Copyright`, `function dql_completed`, `function dql_reset`, `function dql_init`, `export dql_completed`, `export dql_reset`, `export dql_init`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.