linux/mm/damon/sysfs.c

// SPDX-License-Identifier: GPL-2.0
/*
 * DAMON sysfs Interface
 *
 * Copyright (c) 2022 SeongJae Park <[email protected]>
 */

#include <linux/pid.h>
#include <linux/sched.h>
#include <linux/slab.h>

#include "sysfs-common.h"

/*
 * init region directory
 */

struct damon_sysfs_region {};

static struct damon_sysfs_region *damon_sysfs_region_alloc(void)
{}

static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr,
		char *buf)
{}

static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr,
		const char *buf, size_t count)
{}

static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr,
		char *buf)
{}

static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr,
		const char *buf, size_t count)
{}

static void damon_sysfs_region_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_region_start_attr =;

static struct kobj_attribute damon_sysfs_region_end_attr =;

static struct attribute *damon_sysfs_region_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_region_ktype =;

/*
 * init_regions directory
 */

struct damon_sysfs_regions {};

static struct damon_sysfs_regions *damon_sysfs_regions_alloc(void)
{}

static void damon_sysfs_regions_rm_dirs(struct damon_sysfs_regions *regions)
{}

static int damon_sysfs_regions_add_dirs(struct damon_sysfs_regions *regions,
		int nr_regions)
{}

static ssize_t nr_regions_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t nr_regions_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_regions_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_regions_nr_attr =;

static struct attribute *damon_sysfs_regions_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_regions_ktype =;

/*
 * target directory
 */

struct damon_sysfs_target {};

static struct damon_sysfs_target *damon_sysfs_target_alloc(void)
{}

static int damon_sysfs_target_add_dirs(struct damon_sysfs_target *target)
{}

static void damon_sysfs_target_rm_dirs(struct damon_sysfs_target *target)
{}

static ssize_t pid_target_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t pid_target_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_target_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_target_pid_attr =;

static struct attribute *damon_sysfs_target_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_target_ktype =;

/*
 * targets directory
 */

struct damon_sysfs_targets {};

static struct damon_sysfs_targets *damon_sysfs_targets_alloc(void)
{}

static void damon_sysfs_targets_rm_dirs(struct damon_sysfs_targets *targets)
{}

static int damon_sysfs_targets_add_dirs(struct damon_sysfs_targets *targets,
		int nr_targets)
{}

static ssize_t nr_targets_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t nr_targets_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_targets_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_targets_nr_attr =;

static struct attribute *damon_sysfs_targets_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_targets_ktype =;

/*
 * intervals directory
 */

struct damon_sysfs_intervals {};

static struct damon_sysfs_intervals *damon_sysfs_intervals_alloc(
		unsigned long sample_us, unsigned long aggr_us,
		unsigned long update_us)
{}

static ssize_t sample_us_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t sample_us_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static ssize_t aggr_us_show(struct kobject *kobj, struct kobj_attribute *attr,
		char *buf)
{}

static ssize_t aggr_us_store(struct kobject *kobj, struct kobj_attribute *attr,
		const char *buf, size_t count)
{}

static ssize_t update_us_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t update_us_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_intervals_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_intervals_sample_us_attr =;

static struct kobj_attribute damon_sysfs_intervals_aggr_us_attr =;

static struct kobj_attribute damon_sysfs_intervals_update_us_attr =;

static struct attribute *damon_sysfs_intervals_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_intervals_ktype =;

/*
 * monitoring_attrs directory
 */

struct damon_sysfs_attrs {};

static struct damon_sysfs_attrs *damon_sysfs_attrs_alloc(void)
{}

static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs)
{}

static void damon_sysfs_attrs_rm_dirs(struct damon_sysfs_attrs *attrs)
{}

static void damon_sysfs_attrs_release(struct kobject *kobj)
{}

static struct attribute *damon_sysfs_attrs_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_attrs_ktype =;

/*
 * context directory
 */

/* This should match with enum damon_ops_id */
static const char * const damon_sysfs_ops_strs[] =;

struct damon_sysfs_context {};

static struct damon_sysfs_context *damon_sysfs_context_alloc(
		enum damon_ops_id ops_id)
{}

static int damon_sysfs_context_set_attrs(struct damon_sysfs_context *context)
{}

static int damon_sysfs_context_set_targets(struct damon_sysfs_context *context)
{}

static int damon_sysfs_context_set_schemes(struct damon_sysfs_context *context)
{}

static int damon_sysfs_context_add_dirs(struct damon_sysfs_context *context)
{}

static void damon_sysfs_context_rm_dirs(struct damon_sysfs_context *context)
{}

static ssize_t avail_operations_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t operations_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t operations_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_context_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_context_avail_operations_attr =;

static struct kobj_attribute damon_sysfs_context_operations_attr =;

static struct attribute *damon_sysfs_context_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_context_ktype =;

/*
 * contexts directory
 */

struct damon_sysfs_contexts {};

static struct damon_sysfs_contexts *damon_sysfs_contexts_alloc(void)
{}

static void damon_sysfs_contexts_rm_dirs(struct damon_sysfs_contexts *contexts)
{}

static int damon_sysfs_contexts_add_dirs(struct damon_sysfs_contexts *contexts,
		int nr_contexts)
{}

static ssize_t nr_contexts_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t nr_contexts_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_contexts_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_contexts_nr_attr
		=;

static struct attribute *damon_sysfs_contexts_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_contexts_ktype =;

/*
 * kdamond directory
 */

struct damon_sysfs_kdamond {};

static struct damon_sysfs_kdamond *damon_sysfs_kdamond_alloc(void)
{}

static int damon_sysfs_kdamond_add_dirs(struct damon_sysfs_kdamond *kdamond)
{}

static void damon_sysfs_kdamond_rm_dirs(struct damon_sysfs_kdamond *kdamond)
{}

static bool damon_sysfs_ctx_running(struct damon_ctx *ctx)
{}

/*
 * enum damon_sysfs_cmd - Commands for a specific kdamond.
 */
enum damon_sysfs_cmd {};

/* Should match with enum damon_sysfs_cmd */
static const char * const damon_sysfs_cmd_strs[] =;

/*
 * struct damon_sysfs_cmd_request - A request to the DAMON callback.
 * @cmd:	The command that needs to be handled by the callback.
 * @kdamond:	The kobject wrapper that associated to the kdamond thread.
 *
 * This structure represents a sysfs command request that need to access some
 * DAMON context-internal data.  Because DAMON context-internal data can be
 * safely accessed from DAMON callbacks without additional synchronization, the
 * request will be handled by the DAMON callback.  None-``NULL`` @kdamond means
 * the request is valid.
 */
struct damon_sysfs_cmd_request {};

/* Current DAMON callback request.  Protected by damon_sysfs_lock. */
static struct damon_sysfs_cmd_request damon_sysfs_cmd_request;

static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
		char *buf)
{}

static int damon_sysfs_set_attrs(struct damon_ctx *ctx,
		struct damon_sysfs_attrs *sys_attrs)
{}

static void damon_sysfs_destroy_targets(struct damon_ctx *ctx)
{}

static int damon_sysfs_set_regions(struct damon_target *t,
		struct damon_sysfs_regions *sysfs_regions)
{}

static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,
		struct damon_ctx *ctx)
{}

static int damon_sysfs_add_targets(struct damon_ctx *ctx,
		struct damon_sysfs_targets *sysfs_targets)
{}

static bool damon_sysfs_schemes_regions_updating;

static void damon_sysfs_before_terminate(struct damon_ctx *ctx)
{}

/*
 * damon_sysfs_upd_schemes_stats() - Update schemes stats sysfs files.
 * @kdamond:	The kobject wrapper that associated to the kdamond thread.
 *
 * This function reads the schemes stats of specific kdamond and update the
 * related values for sysfs files.  This function should be called from DAMON
 * callbacks while holding ``damon_syfs_lock``, to safely access the DAMON
 * contexts-internal data and DAMON sysfs variables.
 */
static int damon_sysfs_upd_schemes_stats(struct damon_sysfs_kdamond *kdamond)
{}

static int damon_sysfs_upd_schemes_regions_start(
		struct damon_sysfs_kdamond *kdamond, bool total_bytes_only)
{}

static int damon_sysfs_upd_schemes_regions_stop(
		struct damon_sysfs_kdamond *kdamond)
{}

static int damon_sysfs_clear_schemes_regions(
		struct damon_sysfs_kdamond *kdamond)
{}

static inline bool damon_sysfs_kdamond_running(
		struct damon_sysfs_kdamond *kdamond)
{}

static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
		struct damon_sysfs_context *sys_ctx)
{}

static struct damon_ctx *damon_sysfs_build_ctx(
		struct damon_sysfs_context *sys_ctx);

/*
 * damon_sysfs_commit_input() - Commit user inputs to a running kdamond.
 * @kdamond:	The kobject wrapper for the associated kdamond.
 *
 * If the sysfs input is wrong, the kdamond will be terminated.
 */
static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond)
{}

static int damon_sysfs_commit_schemes_quota_goals(
		struct damon_sysfs_kdamond *sysfs_kdamond)
{}

/*
 * damon_sysfs_upd_schemes_effective_quotas() - Update schemes effective quotas
 * sysfs files.
 * @kdamond:	The kobject wrapper that associated to the kdamond thread.
 *
 * This function reads the schemes' effective quotas of specific kdamond and
 * update the related values for sysfs files.  This function should be called
 * from DAMON callbacks while holding ``damon_syfs_lock``, to safely access the
 * DAMON contexts-internal data and DAMON sysfs variables.
 */
static int damon_sysfs_upd_schemes_effective_quotas(
		struct damon_sysfs_kdamond *kdamond)
{}


/*
 * damon_sysfs_cmd_request_callback() - DAMON callback for handling requests.
 * @c:		The DAMON context of the callback.
 * @active:	Whether @c is not deactivated due to watermarks.
 * @after_aggr:	Whether this is called from after_aggregation() callback.
 *
 * This function is periodically called back from the kdamond thread for @c.
 * Then, it checks if there is a waiting DAMON sysfs request and handles it.
 */
static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool active,
		bool after_aggregation)
{}

static int damon_sysfs_after_wmarks_check(struct damon_ctx *c)
{}

static int damon_sysfs_after_sampling(struct damon_ctx *c)
{}

static int damon_sysfs_after_aggregation(struct damon_ctx *c)
{}

static struct damon_ctx *damon_sysfs_build_ctx(
		struct damon_sysfs_context *sys_ctx)
{}

static int damon_sysfs_turn_damon_on(struct damon_sysfs_kdamond *kdamond)
{}

static int damon_sysfs_turn_damon_off(struct damon_sysfs_kdamond *kdamond)
{}

/*
 * damon_sysfs_handle_cmd() - Handle a command for a specific kdamond.
 * @cmd:	The command to handle.
 * @kdamond:	The kobject wrapper for the associated kdamond.
 *
 * This function handles a DAMON sysfs command for a kdamond.  For commands
 * that need to access running DAMON context-internal data, it requests
 * handling of the command to the DAMON callback
 * (@damon_sysfs_cmd_request_callback()) and wait until it is properly handled,
 * or the context is completed.
 *
 * Return: 0 on success, negative error code otherwise.
 */
static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd,
		struct damon_sysfs_kdamond *kdamond)
{}

static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
		const char *buf, size_t count)
{}

static ssize_t pid_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static void damon_sysfs_kdamond_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_kdamond_state_attr =;

static struct kobj_attribute damon_sysfs_kdamond_pid_attr =;

static struct attribute *damon_sysfs_kdamond_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_kdamond_ktype =;

/*
 * kdamonds directory
 */

struct damon_sysfs_kdamonds {};

static struct damon_sysfs_kdamonds *damon_sysfs_kdamonds_alloc(void)
{}

static void damon_sysfs_kdamonds_rm_dirs(struct damon_sysfs_kdamonds *kdamonds)
{}

static bool damon_sysfs_kdamonds_busy(struct damon_sysfs_kdamond **kdamonds,
		int nr_kdamonds)
{}

static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds,
		int nr_kdamonds)
{}

static ssize_t nr_kdamonds_show(struct kobject *kobj,
		struct kobj_attribute *attr, char *buf)
{}

static ssize_t nr_kdamonds_store(struct kobject *kobj,
		struct kobj_attribute *attr, const char *buf, size_t count)
{}

static void damon_sysfs_kdamonds_release(struct kobject *kobj)
{}

static struct kobj_attribute damon_sysfs_kdamonds_nr_attr =;

static struct attribute *damon_sysfs_kdamonds_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_kdamonds_ktype =;

/*
 * damon user interface directory
 */

struct damon_sysfs_ui_dir {};

static struct damon_sysfs_ui_dir *damon_sysfs_ui_dir_alloc(void)
{}

static int damon_sysfs_ui_dir_add_dirs(struct damon_sysfs_ui_dir *ui_dir)
{}

static void damon_sysfs_ui_dir_release(struct kobject *kobj)
{}

static struct attribute *damon_sysfs_ui_dir_attrs[] =;
ATTRIBUTE_GROUPS();

static const struct kobj_type damon_sysfs_ui_dir_ktype =;

static int __init damon_sysfs_init(void)
{}
subsys_initcall(damon_sysfs_init);

#include "sysfs-test.h"