include/rv/da_monitor.h

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

File Facts

System
Linux kernel
Corpus path
include/rv/da_monitor.h
Extension
.h
Size
23053 bytes
Lines
912
Domain
Repository Root And Misc
Bucket
include
Inferred role
Repository Root And Misc: implementation source
Status
source implementation candidate

Why This File Exists

Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.

Dependency Surface

Detected Declarations

Annotated Snippet

struct da_monitor_storage {
	da_id_type id;
	monitor_target target;
	union rv_task_monitor rv;
	struct hlist_node node;
	struct rcu_head rcu;
};

#ifndef DA_MONITOR_HT_BITS
#define DA_MONITOR_HT_BITS 10
#endif
static DEFINE_HASHTABLE(da_monitor_ht, DA_MONITOR_HT_BITS);

/*
 * da_create_empty_storage - pre-allocate an empty storage
 */
static inline struct da_monitor_storage *da_create_empty_storage(da_id_type id)
{
	struct da_monitor_storage *mon_storage;

	mon_storage = kmalloc_nolock(sizeof(struct da_monitor_storage),
				     __GFP_ZERO, NUMA_NO_NODE);
	if (!mon_storage)
		return NULL;

	hash_add_rcu(da_monitor_ht, &mon_storage->node, id);
	mon_storage->id = id;
	return mon_storage;
}

/*
 * da_create_storage - create the per-object storage
 *
 * The caller is responsible to synchronise writers, either with locks or
 * implicitly. For instance, if da_create_storage is only called from a single
 * event for target (e.g. sched_switch), it's safe to call this without locks.
 */
static inline struct da_monitor *da_create_storage(da_id_type id,
						   monitor_target target,
						   struct da_monitor *da_mon)
{
	struct da_monitor_storage *mon_storage;

	if (da_mon)
		return da_mon;

	mon_storage = da_create_empty_storage(id);
	if (!mon_storage)
		return NULL;

	mon_storage->target = target;
	return &mon_storage->rv.da_mon;
}

/*
 * __da_get_mon_storage - get the monitor storage from the hash table
 */
static inline struct da_monitor_storage *__da_get_mon_storage(da_id_type id)
{
	struct da_monitor_storage *mon_storage;

	lockdep_assert_in_rcu_read_lock();
	hash_for_each_possible_rcu(da_monitor_ht, mon_storage, node, id) {
		if (mon_storage->id == id)
			return mon_storage;
	}

	return NULL;
}

/*
 * da_get_monitor - return the monitor for target
 */
static struct da_monitor *da_get_monitor(da_id_type id, monitor_target target)
{
	struct da_monitor_storage *mon_storage;

	mon_storage = __da_get_mon_storage(id);
	return mon_storage ? &mon_storage->rv.da_mon : NULL;
}

/*
 * da_get_target - return the object associated to the monitor
 */
static inline monitor_target da_get_target(struct da_monitor *da_mon)
{
	return container_of(da_mon, struct da_monitor_storage, rv.da_mon)->target;
}

/*

Annotation

Implementation Notes