mirror of
https://github.com/schoebel/mars
synced 2024-12-26 00:22:31 +00:00
proc: show lamport clock in /proc/sys/mars/
This commit is contained in:
parent
af5c95317c
commit
23c4a1cc57
1
brick.c
1
brick.c
@ -607,6 +607,7 @@ EXPORT_SYMBOL_GPL(generic_get_aspect);
|
||||
|
||||
struct semaphore lamport_sem = __SEMAPHORE_INITIALIZER(lamport_sem, 1); // TODO: replace with spinlock if possible (first check)
|
||||
struct timespec lamport_now = {};
|
||||
EXPORT_SYMBOL_GPL(lamport_now);
|
||||
|
||||
void get_lamport(struct timespec *now)
|
||||
{
|
||||
|
2
brick.h
2
brick.h
@ -543,6 +543,8 @@ INLINE struct BRITYPE##_##OBJTYPE##_aspect *BRITYPE##_##OBJTYPE##_get_aspect(str
|
||||
|
||||
// some general helpers
|
||||
|
||||
extern struct timespec lamport_now;
|
||||
|
||||
extern void get_lamport(struct timespec *now);
|
||||
extern void set_lamport(struct timespec *old);
|
||||
|
||||
|
@ -86,6 +86,53 @@ done:
|
||||
return res;
|
||||
}
|
||||
|
||||
static
|
||||
int lamport_sysctl_handler(
|
||||
ctl_table *table,
|
||||
int write,
|
||||
void __user *buffer,
|
||||
size_t *length,
|
||||
loff_t *ppos)
|
||||
{
|
||||
ssize_t res = 0;
|
||||
size_t len = *length;
|
||||
|
||||
MARS_DBG("write = %d len = %ld pos = %lld\n", write, len, *ppos);
|
||||
|
||||
if (!len || *ppos > 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (write) {
|
||||
return -EINVAL;
|
||||
} else {
|
||||
char *tmp = brick_string_alloc(len);
|
||||
struct timespec now = CURRENT_TIME;
|
||||
|
||||
res = snprintf(tmp, len,
|
||||
"CURRENT_TIME=%ld.%09ld\n"
|
||||
"lamport_now=%ld.%09ld\n",
|
||||
now.tv_sec, now.tv_nsec,
|
||||
lamport_now.tv_sec, lamport_now.tv_nsec
|
||||
);
|
||||
|
||||
if (copy_to_user(buffer, tmp, res)) {
|
||||
MARS_ERR("write %ld bytes at %p failed\n", res, buffer);
|
||||
res = -EFAULT;
|
||||
}
|
||||
brick_string_free(tmp);
|
||||
}
|
||||
|
||||
done:
|
||||
MARS_DBG("res = %ld\n", res);
|
||||
*length = res;
|
||||
if (res >= 0) {
|
||||
*ppos += res;
|
||||
return 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MARS_LOADAVG_LIMIT
|
||||
int mars_max_loadavg = 0;
|
||||
EXPORT_SYMBOL_GPL(mars_max_loadavg);
|
||||
@ -145,6 +192,12 @@ ctl_table mars_table[] = {
|
||||
.mode = 0200,
|
||||
.proc_handler = &trigger_sysctl_handler,
|
||||
},
|
||||
{
|
||||
_CTL_NAME
|
||||
.procname = "lamport_clock",
|
||||
.mode = 0400,
|
||||
.proc_handler = &lamport_sysctl_handler,
|
||||
},
|
||||
INT_ENTRY("syslog_min_class", brick_say_syslog_min, 0600),
|
||||
INT_ENTRY("syslog_max_class", brick_say_syslog_max, 0600),
|
||||
INT_ENTRY("delay_say_on_overflow",delay_say_on_overflow, 0600),
|
||||
|
@ -138,6 +138,7 @@ int mars_symlink(const char *oldpath, const char *newpath, const struct timespec
|
||||
if (status >= 0 &&
|
||||
!stat.mtime.tv_nsec &&
|
||||
new_stamp.tv_sec <= stat.mtime.tv_sec) {
|
||||
MARS_DBG("workaround timestamp tv_sec=%ld\n", stat.mtime.tv_sec);
|
||||
new_stamp.tv_sec = stat.mtime.tv_sec + 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user