Commit 0f620301 authored by Adam Wujek's avatar Adam Wujek 💬

arch-wrs: Print error message on multiple shmem locks

Commit based on the commit mentioned below from wr-switch-sw repo.
It required to add a header wrs-msg.h to support "pr_error" function.
"pr_error" will be printed as regular error, all other pr_* are ignored.

userspace/libwr: Print error message on multiple shmem locks

Print error message when shmem is locked or unlocked multiple times.
To be precise it will print error only on even locks or unlocks.

Move the increment of sequence before checking the flags to simplify further
if-conditions.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent ab7106d2
......@@ -69,7 +69,11 @@ void *wrs_shm_follow(void *headptr, void *ptr);
/* Before and after writing a chunk of data, act on sequence and stamp */
#define WRS_SHM_WRITE_BEGIN 1
#define WRS_SHM_WRITE_END 0
extern void wrs_shm_write(void *headptr, int flags);
/* A helper to pass the name of caller function */
#define wrs_shm_write(headptr, flags) wrs_shm_write_caller(headptr, flags, \
__func__)
extern void wrs_shm_write_caller(void *headptr, int flags, const char *caller);
/* A reader can rely on the sequence number (in the <linux/seqlock.h> way) */
extern unsigned wrs_shm_seqbegin(void *headptr);
......
/*
* File to provide printout interfaces used in libwr of wrs-switch-sw
*/
#ifndef __WRS_MSG_H__
#define __WRS_MSG_H__
#include <ppsi/ppsi.h>
/* And shortands for people using autocompletion -- but not all levels */
#define pr_error(...) pp_error(__VA_ARGS__)
#define pr_err(...) pr_error(__VA_ARGS__)
#define pr_warning(...)
#define pr_warn(...)
#define pr_info(...)
#define pr_debug(...)
#endif /* __WRS_MSG_H__ */
......@@ -12,6 +12,7 @@
#include <libwr/shmem.h>
#include <libwr/util.h>
#include <libwr/wrs-msg.h>
#define SHM_LOCK_TIMEOUT_MS 50 /* in ms */
......@@ -197,15 +198,29 @@ void *wrs_shm_follow(void *headptr, void *ptr)
}
/* Before and after writing a chunk of data, act on sequence and stamp */
void wrs_shm_write(void *headptr, int flags)
void wrs_shm_write_caller(void *headptr, int flags, const char *caller)
{
struct wrs_shm_head *head = headptr;
head->sequence++;
pr_debug("caller: %s\n", caller);
if (flags == WRS_SHM_WRITE_END) {
/* At end-of-writing update the timestamp too */
head->stamp = get_monotonic_sec();
if (head->sequence & 1)
pr_error("On the shmem write end the sequence number "
"(%d) is even (should be odd). The caller of"
" wrs_shm_write is %s\n",
head->sequence, caller);
} else {
if (!(head->sequence & 1))
pr_error("On the shmem write begin the sequence number"
" (%d) is odd (should be even). The caller of"
" wrs_shm_write is %s\n",
head->sequence, caller);
}
head->sequence++;
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment