mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-15 22:15:13 +08:00
8cd6440958
Add support for devlink resource abstraction. The resources are represented by a tree based structure and are identified by a name and a size. Some resources can present their real time occupancy. First the resources exposed by the driver can be observed, for example: $devlink resource show pci/0000:03:00.0 pci/0000:03:00.0: name kvd size 245760 unit entry resources: name linear size 98304 occ 0 unit entry size_min 0 size_max 147456 size_gran 128 name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128 name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128 Some resource's size can be changed. Examples: $devlink resource set pci/0000:03:00.0 path /kvd/hash_single size 73088 $devlink resource set pci/0000:03:00.0 path /kvd/hash_double size 74368 The changes do not apply immediately, this can be validate by the 'size_new' attribute, which represents the pending changed size. For example $devlink resource show pci/0000:03:00.0 pci/0000:03:00.0: name kvd size 245760 unit entry size_valid false resources: name linear size 98304 size_new 147456 occ 0 unit entry size_min 0 size_max 147456 size_gran 128 name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128 name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128 In case of a pending change the nested resources present an indication for a valid configuration of its children (sum of its children sizes doesn't exceed the parent's size). In order for the changes to take place hot reload is needed. The hot reload through devlink will be introduced in the following patch. Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
135 lines
3.3 KiB
C
135 lines
3.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LIST_H__
|
|
#define __LIST_H__ 1
|
|
/* List and hash list stuff from kernel */
|
|
|
|
#include <stddef.h>
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
|
|
|
struct list_head {
|
|
struct list_head *next, *prev;
|
|
};
|
|
|
|
static inline void INIT_LIST_HEAD(struct list_head *list)
|
|
{
|
|
list->next = list;
|
|
list->prev = list;
|
|
}
|
|
|
|
static inline void __list_add(struct list_head *new,
|
|
struct list_head *prev,
|
|
struct list_head *next)
|
|
{
|
|
next->prev = new;
|
|
new->next = next;
|
|
new->prev = prev;
|
|
prev->next = new;
|
|
}
|
|
|
|
static inline void list_add(struct list_head *new, struct list_head *head)
|
|
{
|
|
__list_add(new, head, head->next);
|
|
}
|
|
|
|
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
|
{
|
|
__list_add(new, head->prev, head);
|
|
}
|
|
|
|
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
|
{
|
|
next->prev = prev;
|
|
prev->next = next;
|
|
}
|
|
|
|
static inline void list_del(struct list_head *entry)
|
|
{
|
|
__list_del(entry->prev, entry->next);
|
|
}
|
|
|
|
#define list_entry(ptr, type, member) \
|
|
container_of(ptr, type, member)
|
|
|
|
#define list_first_entry(ptr, type, member) \
|
|
list_entry((ptr)->next, type, member)
|
|
|
|
#define list_last_entry(ptr, type, member) \
|
|
list_entry((ptr)->prev, type, member)
|
|
|
|
#define list_next_entry(pos, member) \
|
|
list_entry((pos)->member.next, typeof(*(pos)), member)
|
|
|
|
#define list_prev_entry(pos, member) \
|
|
list_entry((pos)->member.prev, typeof(*(pos)), member)
|
|
|
|
#define list_for_each_entry(pos, head, member) \
|
|
for (pos = list_first_entry(head, typeof(*pos), member); \
|
|
&pos->member != (head); \
|
|
pos = list_next_entry(pos, member))
|
|
|
|
#define list_for_each_entry_safe(pos, n, head, member) \
|
|
for (pos = list_first_entry(head, typeof(*pos), member), \
|
|
n = list_next_entry(pos, member); \
|
|
&pos->member != (head); \
|
|
pos = n, n = list_next_entry(n, member))
|
|
|
|
#define list_for_each_entry_reverse(pos, head, member) \
|
|
for (pos = list_last_entry(head, typeof(*pos), member); \
|
|
&pos->member != (head); \
|
|
pos = list_prev_entry(pos, member))
|
|
|
|
struct hlist_head {
|
|
struct hlist_node *first;
|
|
};
|
|
|
|
struct hlist_node {
|
|
struct hlist_node *next, **pprev;
|
|
};
|
|
|
|
static inline void hlist_del(struct hlist_node *n)
|
|
{
|
|
struct hlist_node *next = n->next;
|
|
struct hlist_node **pprev = n->pprev;
|
|
*pprev = next;
|
|
if (next)
|
|
next->pprev = pprev;
|
|
}
|
|
|
|
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
|
{
|
|
struct hlist_node *first = h->first;
|
|
n->next = first;
|
|
if (first)
|
|
first->pprev = &n->next;
|
|
h->first = n;
|
|
n->pprev = &h->first;
|
|
}
|
|
|
|
static inline int list_empty(const struct list_head *head)
|
|
{
|
|
return head->next == head;
|
|
}
|
|
|
|
#define hlist_for_each(pos, head) \
|
|
for (pos = (head)->first; pos ; pos = pos->next)
|
|
|
|
|
|
#define hlist_for_each_safe(pos, n, head) \
|
|
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
|
pos = n)
|
|
|
|
#define hlist_entry_safe(ptr, type, member) \
|
|
({ typeof(ptr) ____ptr = (ptr); \
|
|
____ptr ? hlist_entry(____ptr, type, member) : NULL; \
|
|
})
|
|
|
|
#define hlist_for_each_entry(pos, head, member) \
|
|
for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
|
|
pos; \
|
|
pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
|
|
|
|
#endif /* __LIST_H__ */
|