drivers/watchdog/watchdog_pretimeout.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/watchdog_pretimeout.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/watchdog_pretimeout.c- Extension
.c- Size
- 4625 bytes
- Lines
- 218
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/list.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/sysfs.hlinux/types.hlinux/watchdog.hwatchdog_core.hwatchdog_pretimeout.h
Detected Declarations
struct watchdog_pretimeoutstruct governor_privfunction watchdog_pretimeout_available_governors_getfunction watchdog_pretimeout_governor_getfunction watchdog_pretimeout_governor_setfunction watchdog_notify_pretimeoutfunction watchdog_register_governorfunction watchdog_unregister_governorfunction list_for_each_entry_safefunction watchdog_register_pretimeoutfunction watchdog_unregister_pretimeoutfunction list_for_each_entry_safeexport watchdog_notify_pretimeoutexport watchdog_register_governorexport watchdog_unregister_governor
Annotated Snippet
struct watchdog_pretimeout {
struct watchdog_device *wdd;
struct list_head entry;
};
/* The mutex protects governor list and serializes external interfaces */
static DEFINE_MUTEX(governor_lock);
/* List of the registered watchdog pretimeout governors */
static LIST_HEAD(governor_list);
struct governor_priv {
struct watchdog_governor *gov;
struct list_head entry;
};
static struct governor_priv *find_governor_by_name(const char *gov_name)
{
struct governor_priv *priv;
list_for_each_entry(priv, &governor_list, entry)
if (sysfs_streq(gov_name, priv->gov->name))
return priv;
return NULL;
}
int watchdog_pretimeout_available_governors_get(char *buf)
{
struct governor_priv *priv;
int count = 0;
mutex_lock(&governor_lock);
list_for_each_entry(priv, &governor_list, entry)
count += sysfs_emit_at(buf, count, "%s\n", priv->gov->name);
mutex_unlock(&governor_lock);
return count;
}
int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf)
{
int count = 0;
spin_lock_irq(&pretimeout_lock);
if (wdd->gov)
count = sysfs_emit(buf, "%s\n", wdd->gov->name);
spin_unlock_irq(&pretimeout_lock);
return count;
}
int watchdog_pretimeout_governor_set(struct watchdog_device *wdd,
const char *buf)
{
struct governor_priv *priv;
mutex_lock(&governor_lock);
priv = find_governor_by_name(buf);
if (!priv) {
mutex_unlock(&governor_lock);
return -EINVAL;
}
spin_lock_irq(&pretimeout_lock);
wdd->gov = priv->gov;
spin_unlock_irq(&pretimeout_lock);
mutex_unlock(&governor_lock);
return 0;
}
void watchdog_notify_pretimeout(struct watchdog_device *wdd)
{
unsigned long flags;
spin_lock_irqsave(&pretimeout_lock, flags);
if (!wdd->gov) {
spin_unlock_irqrestore(&pretimeout_lock, flags);
return;
}
wdd->gov->pretimeout(wdd);
spin_unlock_irqrestore(&pretimeout_lock, flags);
}
EXPORT_SYMBOL_GPL(watchdog_notify_pretimeout);
Annotation
- Immediate include surface: `linux/list.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/string.h`, `linux/sysfs.h`, `linux/types.h`, `linux/watchdog.h`, `watchdog_core.h`.
- Detected declarations: `struct watchdog_pretimeout`, `struct governor_priv`, `function watchdog_pretimeout_available_governors_get`, `function watchdog_pretimeout_governor_get`, `function watchdog_pretimeout_governor_set`, `function watchdog_notify_pretimeout`, `function watchdog_register_governor`, `function watchdog_unregister_governor`, `function list_for_each_entry_safe`, `function watchdog_register_pretimeout`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.