tools/lib/thermal/commands.c
Source file repositories/reference/linux-study-clean/tools/lib/thermal/commands.c
File Facts
- System
- Linux kernel
- Corpus path
tools/lib/thermal/commands.c- Extension
.c- Size
- 13881 bytes
- Lines
- 512
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdio.hstdlib.hunistd.hlimits.hthermal.hthermal_nl.h
Detected Declarations
struct cmd_paramfunction parse_tz_getfunction nla_for_each_nestedfunction parse_cdev_getfunction nla_for_each_nestedfunction parse_tz_get_tripfunction nla_for_each_nestedfunction parse_tz_get_tempfunction parse_tz_get_govfunction parse_threshold_getfunction handle_netlinkfunction thermal_genl_tz_id_encodefunction thermal_genl_threshold_encodefunction thermal_genl_autofunction thermal_cmd_get_tzfunction thermal_cmd_get_cdevfunction thermal_cmd_get_tripfunction thermal_cmd_get_governorfunction thermal_cmd_get_tempfunction thermal_cmd_threshold_getfunction thermal_cmd_threshold_addfunction thermal_cmd_threshold_deletefunction thermal_cmd_threshold_flushfunction thermal_cmd_exitfunction thermal_cmd_init
Annotated Snippet
struct cmd_param {
int tz_id;
int temp;
int direction;
};
typedef int (*cmd_cb_t)(struct nl_msg *, struct cmd_param *);
static int thermal_genl_tz_id_encode(struct nl_msg *msg, struct cmd_param *p)
{
if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_ID, p->tz_id))
return -1;
return 0;
}
static int thermal_genl_threshold_encode(struct nl_msg *msg, struct cmd_param *p)
{
if (thermal_genl_tz_id_encode(msg, p))
return -1;
if (nla_put_u32(msg, THERMAL_GENL_ATTR_THRESHOLD_TEMP, p->temp))
return -1;
if (nla_put_u32(msg, THERMAL_GENL_ATTR_THRESHOLD_DIRECTION, p->direction))
return -1;
return 0;
}
static thermal_error_t thermal_genl_auto(struct thermal_handler *th, cmd_cb_t cmd_cb,
struct cmd_param *param,
int cmd, int flags, void *arg)
{
thermal_error_t ret = THERMAL_ERROR;
struct nl_msg *msg;
void *hdr;
msg = nlmsg_alloc();
if (!msg)
return THERMAL_ERROR;
hdr = genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, thermal_cmd_ops.o_id,
0, flags, cmd, THERMAL_GENL_VERSION);
if (!hdr)
goto out;
if (cmd_cb && cmd_cb(msg, param))
goto out;
if (nl_send_msg(th->sk_cmd, th->cb_cmd, msg, genl_handle_msg, arg))
goto out;
ret = THERMAL_SUCCESS;
out:
nlmsg_free(msg);
return ret;
}
thermal_error_t thermal_cmd_get_tz(struct thermal_handler *th, struct thermal_zone **tz)
{
return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_TZ_GET_ID,
NLM_F_DUMP | NLM_F_ACK, tz);
}
thermal_error_t thermal_cmd_get_cdev(struct thermal_handler *th, struct thermal_cdev **tc)
{
return thermal_genl_auto(th, NULL, NULL, THERMAL_GENL_CMD_CDEV_GET,
NLM_F_DUMP | NLM_F_ACK, tc);
}
thermal_error_t thermal_cmd_get_trip(struct thermal_handler *th, struct thermal_zone *tz)
{
struct cmd_param p = { .tz_id = tz->id };
return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
THERMAL_GENL_CMD_TZ_GET_TRIP, 0, tz);
}
thermal_error_t thermal_cmd_get_governor(struct thermal_handler *th, struct thermal_zone *tz)
{
struct cmd_param p = { .tz_id = tz->id };
return thermal_genl_auto(th, thermal_genl_tz_id_encode, &p,
THERMAL_GENL_CMD_TZ_GET_GOV, 0, tz);
}
thermal_error_t thermal_cmd_get_temp(struct thermal_handler *th, struct thermal_zone *tz)
{
Annotation
- Immediate include surface: `errno.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `limits.h`, `thermal.h`, `thermal_nl.h`.
- Detected declarations: `struct cmd_param`, `function parse_tz_get`, `function nla_for_each_nested`, `function parse_cdev_get`, `function nla_for_each_nested`, `function parse_tz_get_trip`, `function nla_for_each_nested`, `function parse_tz_get_temp`, `function parse_tz_get_gov`, `function parse_threshold_get`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.