Skip to content

Commit

Permalink
remove provider handle refcount
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Jul 1, 2024
1 parent 5b508d3 commit feaeecd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion include/dpusm/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ typedef struct dpusm_provider_handle {
struct module *module;
dpusm_pc_t capabilities; /* constant set of capabilities */
const dpusm_pf_t *funcs; /* reference to a struct */
atomic_t refs; /* how many users are holding this provider */
struct list_head list;
struct dpusm_provider_handle *self;
} dpusm_ph_t;
Expand Down
23 changes: 10 additions & 13 deletions src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ dpusmph_init(struct module *module, const dpusm_pf_t *funcs)
dpusmph->module = module;
dpusmph->funcs = funcs;
dpusmph->self = dpusmph;
atomic_set(&dpusmph->refs, 0);
}

return dpusmph;
Expand All @@ -236,6 +235,7 @@ dpusmph_init(struct module *module, const dpusm_pf_t *funcs)
/* add a new provider */
int
dpusm_provider_register(dpusm_t *dpusm, struct module *module, const dpusm_pf_t *funcs) {
printk("refcount %d\n", module_refcount(module));
const int rc = dpusm_provider_sane_at_load(funcs);
if (rc != DPUSM_OK) {
static const size_t max =
Expand Down Expand Up @@ -263,7 +263,6 @@ dpusm_provider_register(dpusm_t *dpusm, struct module *module, const dpusm_pf_t

dpusm_mem_free(buf, size);

/* module_put(module); */
return -EINVAL;
}

Expand All @@ -274,14 +273,12 @@ dpusm_provider_register(dpusm_t *dpusm, struct module *module, const dpusm_pf_t
printk("%s: DPUSM Provider with the name \"%s\" (%p) already exists. %zu providers registered.\n",
__func__, module_name(module), *found, dpusm->count);
dpusm_provider_write_unlock(dpusm);
/* module_put(module); */
return -EEXIST;
}

dpusm_ph_t *provider = dpusmph_init(module, funcs);
if (!provider) {
dpusm_provider_write_unlock(dpusm);
/* module_put(module); */
return -ECANCELED;
}

Expand All @@ -304,7 +301,7 @@ dpusm_provider_unregister_handle(dpusm_t *dpusm, dpusm_ph_t **provider) {
}

int rc = 0;
const int refs = atomic_read(&(*provider)->refs);
const int refs = module_refcount((*provider)->module) - 1;
if (refs) {
printk("%s: Unregistering provider \"%s\" with %d references remaining.\n",
__func__, module_name((*provider)->module), refs);
Expand Down Expand Up @@ -358,11 +355,10 @@ dpusm_provider_get(dpusm_t *dpusm, const char *name) {
return NULL;
}

atomic_inc(&(*provider)->refs);
atomic_inc(&dpusm->active);

printk("%s: User has been given a handle to \"%s\" (%p) (now %d users).\n",
__func__, name, *provider, atomic_read(&(*provider)->refs));
__func__, name, *provider, module_refcount((*provider)->module) - 1);

if ((*provider)->funcs->at_connect) {
(*provider)->funcs->at_connect();
Expand All @@ -385,14 +381,15 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
return DPUSM_ERROR;
}

if (!atomic_read(&(*provider)->refs)) {
struct module *module = (*provider)->module;

if (module_refcount(module) == 1) {
printk("%s Error: Cannot decrement provider \"%s\" user count already at 0.\n",
__func__, module_name((*provider)->module));
__func__, module_name(module));
return DPUSM_ERROR;
}

module_put((*provider)->module);
atomic_dec(&(*provider)->refs);
module_put(module);
atomic_dec(&dpusm->active);

if ((*provider)->funcs) { /* provider might have been invalidated */
Expand All @@ -402,7 +399,7 @@ dpusm_provider_put(dpusm_t *dpusm, void *handle) {
}

printk("%s: User has returned a handle to \"%s\" (%p) (now %d users).\n",
__func__, module_name((*provider)->module), *provider, atomic_read(&(*provider)->refs));
__func__, module_name(module), *provider, module_refcount(module) - 1);
return DPUSM_OK;
}

Expand All @@ -423,7 +420,7 @@ void dpusm_provider_invalidate(dpusm_t *dpusm, const char *name) {
(*provider)->funcs = NULL;
memset(&(*provider)->capabilities, 0, sizeof((*provider)->capabilities));
printk("%s: Provider \"%s\" has been invalidated with %d users active.\n",
__func__, name, atomic_read(&(*provider)->refs));
__func__, name, module_refcount((*provider)->module) - 1);
/* not decrementing module reference count here - provider is still registered */
}
else {
Expand Down

0 comments on commit feaeecd

Please sign in to comment.