Module: xenomai-rpm Branch: queue/vfile Commit: 8b22cf66437abe0113d519273dc8ed53c7c613e4 URL: http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=8b22cf66437abe0113d519273dc8ed53c7c613e4
Author: Philippe Gerum <r...@xenomai.org> Date: Sun May 16 13:34:34 2010 +0200 nucleus/shadow: convert to vfile --- include/nucleus/shadow.h | 11 ---- ksrc/nucleus/shadow.c | 151 +++++++++++++++++++++++---------------------- 2 files changed, 77 insertions(+), 85 deletions(-) diff --git a/include/nucleus/shadow.h b/include/nucleus/shadow.h index 93e4206..1615ec8 100644 --- a/include/nucleus/shadow.h +++ b/include/nucleus/shadow.h @@ -54,11 +54,6 @@ struct xnskin_props { struct module *module; }; -struct xnskin_slot { - struct xnskin_props *props; - atomic_counter_t refcnt; -}; - int xnshadow_mount(void); void xnshadow_cleanup(void); @@ -103,8 +98,6 @@ void xnshadow_send_sig(struct xnthread *thread, void xnshadow_rpi_check(void); -extern struct xnskin_slot muxtable[]; - int xnshadow_mark_sig(struct xnthread *thread, unsigned muxid); void xnshadow_clear_sig(struct xnthread *thread, unsigned muxid); @@ -128,13 +121,9 @@ static inline void xnshadow_call_mayday(struct xnthread *thread) #if defined(CONFIG_XENO_OPT_PERVASIVE) && defined(CONFIG_PROC_FS) void xnshadow_init_proc(void); void xnshadow_cleanup_proc(void); -void xnshadow_declare_proc(struct xnskin_slot *iface); -void xnshadow_remove_proc(const char *iface); #else static inline void xnshadow_init_proc(void) { } static inline void xnshadow_cleanup_proc(void) { } -#define xnshadow_declare_proc(iface) do { (void)iface; } while(0) -#define xnshadow_remove_proc(iface) do { (void)name; } while(0) #endif /* CONFIG_XENO_OPT_PERVASIVE && CONFIG_PROC_FS */ #endif /* !_XENO_NUCLEUS_SHADOW_H */ diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c index 80b9caa..c128762 100644 --- a/ksrc/nucleus/shadow.c +++ b/ksrc/nucleus/shadow.c @@ -66,7 +66,13 @@ EXPORT_SYMBOL_GPL(nkthrptd); int nkerrptd; EXPORT_SYMBOL_GPL(nkerrptd); -struct xnskin_slot muxtable[XENOMAI_MUX_NR]; +struct xnskin_slot { + struct xnskin_props *props; + atomic_counter_t refcnt; +#ifdef CONFIG_PROC_FS + struct xnvfile_regular vfile; +#endif +} muxtable[XENOMAI_MUX_NR]; static int lostage_apc; @@ -102,6 +108,8 @@ static int nucleus_muxid = -1; static DECLARE_MUTEX(completion_mutex); +static DECLARE_MUTEX(registration_mutex); + static inline struct task_struct *get_switch_lock_owner(void) { return switch_lock_owner[task_cpu(current)]; @@ -2780,6 +2788,44 @@ static inline void do_cleanup_event(struct mm_struct *mm) RTHAL_DECLARE_CLEANUP_EVENT(cleanup_event); +#ifdef CONFIG_PROC_FS + +static struct xnvfile_directory iface_vfroot; + +static int iface_vfile_show(struct xnvfile_regular_iterator *it, void *data) +{ + struct xnskin_slot *iface; + int refcnt; + + iface = container_of(it->vfile, struct xnskin_slot, vfile); + refcnt = xnarch_atomic_get(&iface->refcnt); + xnvfile_printf(it, "%d\n", refcnt); + + return 0; +} + +static struct xnvfile_regular_ops iface_vfile_ops = { + .show = iface_vfile_show, +}; + +void xnshadow_init_proc(void) +{ + xnvfile_init_dir("interfaces", &iface_vfroot, &nkvfroot); +} + +void xnshadow_cleanup_proc(void) +{ + int muxid; + + for (muxid = 0; muxid < XENOMAI_MUX_NR; muxid++) + if (muxtable[muxid].props && muxtable[muxid].props->name) + xnvfile_destroy_regular(&muxtable[muxid].vfile); + + xnvfile_destroy_dir(&iface_vfroot); +} + +#endif /* CONFIG_PROC_FS */ + /* * xnshadow_register_interface() -- Register a new skin/interface. * NOTE: an interface can be registered without its pod being @@ -2804,6 +2850,7 @@ RTHAL_DECLARE_CLEANUP_EVENT(cleanup_event); int xnshadow_register_interface(struct xnskin_props *props) { + struct xnskin_slot *iface; int muxid; spl_t s; @@ -2814,22 +2861,34 @@ int xnshadow_register_interface(struct xnskin_props *props) if (XENOMAI_MAX_SYSENT < props->nrcalls || 0 > props->nrcalls) return -EINVAL; + down(®istration_mutex); + xnlock_get_irqsave(&nklock, s); for (muxid = 0; muxid < XENOMAI_MUX_NR; muxid++) { - if (muxtable[muxid].props == NULL) { - muxtable[muxid].props = props; - xnarch_atomic_set(&muxtable[muxid].refcnt, 0); + iface = muxtable + muxid; + if (iface->props == NULL) { + iface->props = props; + xnarch_atomic_set(&iface->refcnt, 0); break; } } xnlock_put_irqrestore(&nklock, s); - if (muxid >= XENOMAI_MUX_NR) + if (muxid >= XENOMAI_MUX_NR) { + up(®istration_mutex); return -ENOBUFS; + } - xnshadow_declare_proc(muxtable + muxid); +#ifdef CONFIG_PROC_FS + memset(&iface->vfile, 0, sizeof(iface->vfile)); + iface->vfile.ops = &iface_vfile_ops; + xnvfile_init_regular(props->name, &iface->vfile, + &iface_vfroot); +#endif + + up(®istration_mutex); return muxid; @@ -2843,25 +2902,29 @@ EXPORT_SYMBOL_GPL(xnshadow_register_interface); */ int xnshadow_unregister_interface(int muxid) { - const char *name; + struct xnskin_slot *iface; spl_t s; if (muxid < 0 || muxid >= XENOMAI_MUX_NR) return -EINVAL; - xnlock_get_irqsave(&nklock, s); + down(®istration_mutex); - if (xnarch_atomic_get(&muxtable[muxid].refcnt) > 0) { + xnlock_get_irqsave(&nklock, s); + iface = muxtable + muxid; + if (xnarch_atomic_get(&iface->refcnt) > 0) { xnlock_put_irqrestore(&nklock, s); + up(®istration_mutex); return -EBUSY; } - - name = muxtable[muxid].props->name; - muxtable[muxid].props = NULL; - + iface->props = NULL; xnlock_put_irqrestore(&nklock, s); - xnshadow_remove_proc(name); +#ifdef CONFIG_PROC_FS + xnvfile_destroy_regular(&iface->vfile); +#endif + + up(®istration_mutex); return 0; } @@ -3024,64 +3087,4 @@ void xnshadow_cleanup(void) mayday_cleanup_page(); } -#ifdef CONFIG_PROC_FS - -#include <linux/proc_fs.h> - -static struct proc_dir_entry *iface_proc_root; - -static int iface_read_proc(char *page, - char **start, - off_t off, int count, int *eof, void *data) -{ - struct xnskin_slot *iface = data; - int len, refcnt; - - refcnt = xnarch_atomic_get(&iface->refcnt); - len = sprintf(page, "%d\n", refcnt); - - len -= off; - if (len <= off + count) - *eof = 1; - *start = page + off; - if (len > count) - len = count; - if (len < 0) - len = 0; - - return len; -} - -void xnshadow_declare_proc(struct xnskin_slot *iface) -{ - rthal_add_proc_leaf(iface->props->name, - &iface_read_proc, NULL, iface, - iface_proc_root); -} - -void xnshadow_remove_proc(const char *iface_name) -{ - remove_proc_entry(iface_name, iface_proc_root); -} - -void xnshadow_init_proc(void) -{ - iface_proc_root = - create_proc_entry("interfaces", S_IFDIR, rthal_proc_root); -} - -void xnshadow_cleanup_proc(void) -{ - int muxid; - - for (muxid = 0; muxid < XENOMAI_MUX_NR; muxid++) - if (muxtable[muxid].props && muxtable[muxid].props->name) - remove_proc_entry(muxtable[muxid].props->name, - iface_proc_root); - - remove_proc_entry("interfaces", rthal_proc_root); -} - -#endif /* CONFIG_PROC_FS */ - /*...@}*/ _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git