]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukstore: Lookup entries by id
authorMichalis Pappas <michalis@unikraft.io>
Tue, 6 Jun 2023 09:31:50 +0000 (11:31 +0200)
committerUnikraft <monkey@unikraft.io>
Thu, 17 Aug 2023 21:26:47 +0000 (21:26 +0000)
Introduce an id property to uk_store entries and replace name with id
on lookup operations, to avoid costly string comparison.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@unikraft.io>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #939

lib/ukstore/include/uk/store.h
lib/ukstore/store.c

index f153150e1884a662fcd6599a04c2e724ab60217a..7b04794adc4b8e067b16067f270b502b6a2de357 100644 (file)
@@ -126,6 +126,9 @@ struct uk_store_entry {
                uk_store_set_charp_func_t charp;
        } set;
 
+       /* Entry unique id */
+       __u64 id;
+
        /* The entry name */
        char *name;
 
@@ -142,30 +145,32 @@ struct uk_store_entry {
 #if !CONFIG_LIBUKSTORE
 
 /* Do not call directly */
-#define __UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)  \
+#define __UK_STORE_STATIC_ENTRY(eid, entry, lib_str, e_type, e_get, e_set)\
        static const struct uk_store_entry                              \
        __unused __uk_store_entries_list ## _ ## entry = {              \
-               .name = STRINGIFY(entry),                               \
-               .type       = (UK_STORE_ENTRY_TYPE(e_type)),            \
+               .id             = eid,                                  \
+               .name           = STRINGIFY(entry),                     \
+               .type           = (UK_STORE_ENTRY_TYPE(e_type)),        \
                .get.e_type = (e_get),                                  \
                .set.e_type = (e_set),                                  \
-               .flags      = UK_STORE_ENTRY_FLAG_STATIC                \
+               .flags          = UK_STORE_ENTRY_FLAG_STATIC            \
        }
 
 /* Do not call directly */
-#define _UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)   \
-       __UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)
+#define _UK_STORE_STATIC_ENTRY(id, entry, lib_str, e_type, e_get, e_set)\
+       __UK_STORE_STATIC_ENTRY(id, entry, lib_str, e_type, e_get, e_set)
 
 /**
  * Adds an entry to the entry section of a library.
  *
+ * @param id entry id
  * @param entry the entry in the section
  * @param e_type type for the entry, e.g., s8, u16, charp
  * @param e_get getter pointer (optional, can be NULL)
  * @param e_set setter pointer (optional, can be NULL)
  */
-#define UK_STORE_STATIC_ENTRY(entry, e_type, e_get, e_set)     \
-       _UK_STORE_STATIC_ENTRY(entry, STRINGIFY(__LIBNAME__),   \
+#define UK_STORE_STATIC_ENTRY(id, entry, e_type, e_get, e_set)         \
+       _UK_STORE_STATIC_ENTRY(id, entry, STRINGIFY(__LIBNAME__),       \
                               e_type, e_get, e_set)
 
 #else /* !CONFIG_LIBUKSTORE */
@@ -183,53 +188,52 @@ struct uk_store_entry {
        ((entry)->flags & UK_STORE_ENTRY_FLAG_STATIC)
 
 /* Do not call directly */
-#define __UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)  \
+#define __UK_STORE_STATIC_ENTRY(eid, entry, lib_str, e_type, e_get, e_set)\
        static const struct uk_store_entry                              \
        __used __section(".uk_store_lib_" lib_str) __align8             \
        __uk_store_entries_list ## _ ## entry = {                       \
-               .name = STRINGIFY(entry),                               \
-               .type       = (UK_STORE_ENTRY_TYPE(e_type)),            \
+               .id             = eid,                                  \
+               .name           = STRINGIFY(entry),                     \
+               .type           = (UK_STORE_ENTRY_TYPE(e_type)),        \
                .get.e_type = (e_get),                                  \
                .set.e_type = (e_set),                                  \
-               .flags      = UK_STORE_ENTRY_FLAG_STATIC                \
+               .flags          = UK_STORE_ENTRY_FLAG_STATIC            \
        }
 
 /* Do not call directly */
-#define _UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)   \
-       __UK_STORE_STATIC_ENTRY(entry, lib_str, e_type, e_get, e_set)
+#define _UK_STORE_STATIC_ENTRY(id, entry, lib_str, e_type, e_get, e_set)\
+       __UK_STORE_STATIC_ENTRY(id, entry, lib_str, e_type, e_get, e_set)
 
 /**
  * Adds an entry to the entry section of a library.
  *
+ * @param id entry id
  * @param entry the entry in the section
  * @param e_type type for the entry, e.g., s8, u16, charp
  * @param e_get getter pointer (optional, can be NULL)
  * @param e_set setter pointer (optional, can be NULL)
  */
-#define UK_STORE_STATIC_ENTRY(entry, e_type, e_get, e_set)     \
-       _UK_STORE_STATIC_ENTRY(entry, STRINGIFY(__LIBNAME__),   \
+#define UK_STORE_STATIC_ENTRY(id, entry, e_type, e_get, e_set)         \
+       _UK_STORE_STATIC_ENTRY(id, entry, STRINGIFY(__LIBNAME__),       \
                               e_type, e_get, e_set)
 
 const struct uk_store_entry *
-_uk_store_get_static_entry(__u16 libid, const char *e_name);
-
-static inline const struct uk_store_entry *
-_uk_store_get_entry(__u16 libid, const char *f_name __unused,
-                       const char *e_name)
-{
-       return _uk_store_get_static_entry(libid, e_name);
-}
+_uk_store_get_static_entry(__u16 library_id, __u64 entry_id);
 
 /**
- * Searches for an entry in a folder in a library. Increases the refcount.
+ * Searches for an entry in an object in a library. Increases the refcount.
  *
- * @param libname the name of the library to search in
- * @param foldername the name of the folder to search (NULL for static entries)
- * @param entryname the name of the entry to search for
+ * @param library_id the id of the library to search in
+ * @param object_id the id of the object to search (NULL for static entries)
+ * @param entry_id the id of the entry to search for
  * @return the found entry or NULL
  */
-#define uk_store_get_entry(libname, foldername, entryname)     \
-       _uk_store_get_entry(uk_libid(libname), foldername, entryname)
+static inline const struct uk_store_entry *
+uk_store_get_entry(__u16 library_id, __u64 object_id __unused,
+                  __u64 entry_id)
+{
+       return _uk_store_get_static_entry(library_id, entry_id);
+}
 
 /**
  * Decreases the refcount. When it reaches 0, the memory is freed
index 0757eff0f98d67062531ab79fac3f69e107ce95b..ea47f904719e030b1dac302ebff547232c482d86 100644 (file)
@@ -63,21 +63,14 @@ _uk_store_release_entry(const struct uk_store_entry *p_entry)
                return;
 }
 
-/**
- * Find a static entry and returns it.
- *
- * @param libid the id of the library to search in
- * @param e_name the name of the entry to search for
- * @return the found entry or NULL
- */
 const struct uk_store_entry *
-_uk_store_get_static_entry(__u16 libid, const char *e_name)
+_uk_store_get_static_entry(__u16 libid, __u64 entry_id)
 {
        struct uk_store_entry *entry = static_entries[2 * libid];
        struct uk_store_entry *stop = static_entries[2 * libid + 1];
 
        for (; entry != stop; ++entry)
-               if (!strcmp(entry->name, e_name))
+               if (entry->id == entry_id)
                        return entry;
 
        return NULL;