Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
Beam Positoning Monitor - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Beam Positoning Monitor - Software
Commits
1d4a7536
Commit
1d4a7536
authored
Mar 04, 2015
by
Lucas Russo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hal/dev_io/dev_io_core.*: fix hash insertion on SMIO init
This fixed #79 github issue
parent
9018bc3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
60 deletions
+83
-60
dev_io_core.c
hal/dev_io/dev_io_core.c
+82
-59
dev_io_core.h
hal/dev_io/dev_io_core.h
+1
-1
No files found.
hal/dev_io/dev_io_core.c
View file @
1d4a7536
...
...
@@ -50,8 +50,9 @@
/* Do the SMIO operation */
static
devio_err_e
_devio_do_smio_op
(
devio_t
*
self
,
void
*
msg
);
static
void
_devio_destroy_smio
(
devio_t
*
self
,
uint32_t
smio_id
);
static
void
_devio_destroy_smio_all
(
devio_t
*
self
);
static
devio_err_e
_devio_send_destruct_msg
(
devio_t
*
self
,
void
*
pipe
);
static
devio_err_e
_devio_destroy_smio
(
devio_t
*
self
,
const
char
*
smio_key
);
static
devio_err_e
_devio_destroy_smio_all
(
devio_t
*
self
);
/* Creates a new instance of Device Information */
devio_t
*
devio_new
(
char
*
name
,
char
*
endpoint_dev
,
llio_type_e
type
,
...
...
@@ -233,9 +234,9 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
* the sm_io module */
th_boot_args_t
*
th_args
=
NULL
;
th_config_args_t
*
th_config_args
=
NULL
;
char
*
smio_service
=
NULL
;
void
*
config_pipe
=
NULL
;
char
*
key
=
NULL
;
uint32_t
pipe_idx
=
0
;
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] smio_mod_dispatch table size = %ld
\n
"
,
...
...
@@ -251,11 +252,20 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
/* Found! Call bootstrap code and insert in
* hash table */
/* FIXME: Why do I need this? smio always gets initilized
* after smio_mod_dispatch[i].bootstrap_ops->smio_boot (self); */
/* smio_t *smio = NULL; */
/* It is expected tha after the boot () call the operations
* this sm_io inscate can handle are already registered! */
/* Stringify ID. We do it before spawning a new thread as
* alloc can fail */
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] Stringify hash ID
\n
"
);
char
*
inst_id_str
=
halutils_stringify_dec_key
(
inst_id
);
ASSERT_ALLOC
(
inst_id_str
,
err_inst_id_str_alloc
);
char
*
key
=
halutils_concat_strings_no_sep
(
smio_mod_dispatch
[
th_args
->
smio_id
].
name
,
inst_id_str
);
/* We don't need this anymore */
free
(
inst_id_str
);
inst_id_str
=
NULL
;
ASSERT_ALLOC
(
key
,
err_key_alloc
);
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] Allocating thread args
\n
"
);
...
...
@@ -276,42 +286,25 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] Calling boot func
\n
"
);
uint32_t
pipe_idx
=
self
->
nnodes
++
;
pipe_idx
=
self
->
nnodes
++
;
self
->
pipes
[
pipe_idx
]
=
zthread_fork
(
self
->
ctx
,
smio_startup
,
th_args
);
ASSERT_TEST
(
self
->
pipes
[
pipe_idx
]
!=
NULL
,
"Could not spawn SMIO thread"
,
err_spawn_smio_thread
);
/* self->pipes [pipe_idx] = zthread_fork (self->ctx,
smio_mod_dispatch[i].bootstrap_ops->thread_boot, th_args); */
/*smio = smio_mod_dispatch[i].bootstrap_ops->boot (self);*/
/*ASSERT_ALLOC (smio, err_smio_alloc); */
/* Stringify ID */
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] Stringify hash ID
\n
"
);
char
*
inst_id_str
=
halutils_stringify_dec_key
(
inst_id
);
ASSERT_ALLOC
(
inst_id_str
,
err_inst_id_str_alloc
);
char
*
key
=
halutils_concat_strings_no_sep
(
smio_mod_dispatch
[
th_args
->
smio_id
].
name
,
inst_id_str
);
/* We don't need this anymore */
free
(
inst_id_str
);
inst_id_str
=
NULL
;
ASSERT_ALLOC
(
key
,
err_key_alloc
);
DBE_DEBUG
(
DBG_DEV_IO
|
DBG_LVL_TRACE
,
"[dev_io_core:register_sm] Inserting hash with key: %s
\n
"
,
key
);
int
zerr
=
zhash_insert
(
self
->
sm_io_h
,
key
,
self
->
pipes
[
pipe_idx
]);
/* We must not fail here, as we will loose our reference to the SMIO
* thread otherwise */
ASSERT_TEST
(
zerr
==
0
,
"Could not insert PIPE hash key. Duplicated value?"
,
err_pipe_hash_insert
);
/* Configure default values of the recently created SMIO using the
* bootstrap registered function config_defaults () */
smio_service
=
halutils_concat_strings
(
th_args
->
service
,
smio_mod_dispatch
[
th_args
->
smio_id
].
name
,
':'
);
ASSERT_ALLOC
(
smio_service
,
err_smio_service_alloc
);
/* Now, we create a short lived thread just to configure our SMIO */
/* Allo
a
cate config thread arguments struct and pass it to the
/* Allocate config thread arguments struct and pass it to the
* thread. It is the responsability of the calling thread
* to clear this structure after using it! */
th_config_args
=
zmalloc
(
sizeof
*
th_config_args
);
...
...
@@ -332,28 +325,27 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
break
;
}
/* On success, just "key"" is not deallocated. All of the other
* allocated parameters are either free'd or its ownership
* is transfered to the calling function/thread */
free
(
key
);
return
DEVIO_SUCCESS
;
err_spawn_config_thread:
free
(
smio_service
);
/* FIXME: Destroy SMIO thread as we could configure it? */
free
(
th_config_args
);
/* FIXME: Destroy SMIO thread? */
_devio_destroy_smio
(
self
,
smio_id
);
err_th_config_args_alloc:
free
(
smio_service
);
err_smio_service_alloc:
zhash_delete
(
self
->
sm_io_h
,
key
);
err_pipe_hash_insert:
free
(
key
);
err_key_alloc:
free
(
inst_id_str
);
err_inst_id_str_alloc:
/* This is safe to call more than once */
_devio_destroy_smio
(
self
,
smio_id
);
/* If we can't insert the SMIO thread key in hash,
* destroy it as we won't have a reference to it later! */
_devio_send_destruct_msg
(
self
,
self
->
pipes
[
pipe_idx
]);
err_spawn_smio_thread:
free
(
th_args
);
err_th_args_alloc:
free
(
key
);
err_key_alloc:
err_inst_id_str_alloc:
return
DEVIO_ERR_ALLOC
;
}
...
...
@@ -367,15 +359,12 @@ devio_err_e devio_register_all_sm (devio_t *self)
devio_err_e
devio_unregister_sm
(
devio_t
*
self
,
const
char
*
smio_key
)
{
_devio_destroy_smio
(
self
,
smio_key
);
return
DEVIO_ERR_FUNC_NOT_IMPL
;
return
_devio_destroy_smio
(
self
,
smio_key
);
}
devio_err_e
devio_unregister_all_sm
(
devio_t
*
self
)
{
(
void
)
self
;
return
DEVIO_ERR_FUNC_NOT_IMPL
;
return
_devio_destroy_smio_all
(
self
);
}
devio_err_e
devio_init_poller_sm
(
devio_t
*
self
)
...
...
@@ -527,56 +516,90 @@ err_hand_req:
return
err
;
}
static
void
_devio_destroy_smio_all
(
devio_t
*
self
)
static
devio_err_e
_devio_destroy_smio_all
(
devio_t
*
self
)
{
assert
(
self
);
devio_err_e
err
=
DEVIO_SUCCESS
;
/* Get all hash keys */
zlist_t
*
hash_keys
=
zhash_keys
(
self
->
sm_io_h
);
ASSERT_ALLOC
(
hash_keys
,
err_hash_keys_alloc
);
ASSERT_ALLOC
(
hash_keys
,
err_hash_keys_alloc
,
DEVIO_ERR_ALLOC
);
char
*
hash_item
=
zlist_first
(
hash_keys
);
/* Iterate over all keys removing each of one */
for
(;
hash_item
!=
NULL
;
hash_item
=
zlist_next
(
hash_keys
))
{
_devio_destroy_smio
(
self
,
hash_item
);
err
=
_devio_destroy_smio
(
self
,
hash_item
);
ASSERT_TEST
(
err
==
DEVIO_SUCCESS
,
"Could not destroy SMIO "
"instance"
,
err_smio_destroy
,
DEVIO_ERR_SMIO_DESTROY
);
}
err_smio_destroy:
zlist_destroy
(
&
hash_keys
);
err_hash_keys_alloc:
return
;
return
err
;
}
static
devio_err_e
_devio_send_destruct_msg
(
devio_t
*
self
,
void
*
pipe
)
{
assert
(
self
);
assert
(
pipe
);
devio_err_e
err
=
DEVIO_SUCCESS
;
/* Send message to SMIO informing it to destroy itself */
/* This cannot fail at this point... but it can */
zmsg_t
*
send_msg
=
zmsg_new
();
ASSERT_ALLOC
(
send_msg
,
err_msg_alloc
,
DEVIO_ERR_ALLOC
);
/* An empty message means to selfdestruct */
zmsg_pushstr
(
send_msg
,
""
);
int
zerr
=
zmsg_send
(
&
send_msg
,
pipe
);
ASSERT_TEST
(
zerr
==
0
,
"Could not send self-destruct message to SMIO instance"
,
err_send_msg
,
DEVIO_ERR_SMIO_DESTROY
);
DBE_DEBUG
(
DBG_DEV_MNGR
|
DBG_LVL_INFO
,
"[dev_io_core] Self-destruct message "
"to SMIO sent"
);
err_send_msg:
zmsg_destroy
(
&
send_msg
);
err_msg_alloc:
return
err
;
}
/* smio_key is the name of the SMIO + instance number, e.g.,
* FMC130M_4CH0*/
static
void
_devio_destroy_smio
(
devio_t
*
self
,
const
char
*
smio_key
)
static
devio_err_e
_devio_destroy_smio
(
devio_t
*
self
,
const
char
*
smio_key
)
{
assert
(
self
);
devio_err_e
err
=
DEVIO_SUCCESS
;
/* Lookup SMIO reference in hash table */
void
*
pipe
=
zhash_lookup
(
self
->
sm_io_h
,
smio_key
);
ASSERT_TEST
(
pipe
!=
NULL
,
"Could not find SMIO registered with this ID"
,
err_hash_lookup
);
err_hash_lookup
,
DEVIO_ERR_SMIO_DESTROY
);
#if 0
/* Send message to SMIO informing it to destroy itself */
/* This cannot fail at this point... but it can */
zmsg_t *send_msg = zmsg_new ();
ASSERT_ALLOC
(
send_msg
,
err_msg_alloc
);
ASSERT_ALLOC (send_msg, err_msg_alloc
, DEVIO_ERR_ALLOC
);
/* An empty message means to selfdestruct */
zmsg_pushstr (send_msg, "");
int zerr = zmsg_send (&send_msg, pipe);
ASSERT_TEST (zerr == 0, "Could not send self-destruct message to SMIO instance",
err_send_msg
);
err_send_msg
, DEVIO_ERR_SMIO_DESTROY
);
DBE_DEBUG (DBG_DEV_MNGR | DBG_LVL_INFO, "[dev_io_core] Self-destruct message "
"to SMIO %s sent", smio_key);
#endif
err
=
_devio_send_destruct_msg
(
self
,
pipe
);
ASSERT_TEST
(
err
==
DEVIO_SUCCESS
,
"Could not send self-destruct message to "
"PIPE"
,
err_send_msg
,
DEVIO_ERR_SMIO_DESTROY
);
/* Finally, remove the pipe from hash */
/* Finally, remove the pipe from hash. FIXME: What if the SMIO does not
* exit? We will loose its reference ...*/
zhash_delete
(
self
->
sm_io_h
,
smio_key
);
err_send_msg:
zmsg_destroy
(
&
send_msg
);
err_msg_alloc:
err_hash_lookup:
err_key_alloc:
return
;
return
err
;
}
hal/dev_io/dev_io_core.h
View file @
1d4a7536
...
...
@@ -97,7 +97,7 @@ devio_err_e devio_register_sm (devio_t *self, uint32_t smio_id, uint32_t base,
/* Register all sm_io module that this device can handle,
* according to the device information stored in the SDB */
devio_err_e
devio_register_all_sm
(
devio_t
*
self
);
devio_err_e
devio_unregister_sm
(
devio_t
*
self
,
uint32_t
smio_id
,
uint32_t
inst_id
);
devio_err_e
devio_unregister_sm
(
devio_t
*
self
,
const
char
*
smio_key
);
devio_err_e
devio_unregister_all_sm
(
devio_t
*
self
);
/* Initilize poller with all of the initialized PIPE sockets */
devio_err_e
devio_init_poller_sm
(
devio_t
*
self
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment