]> sourceware.org Git - systemtap.git/commitdiff
2007-11-01 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Thu, 1 Nov 2007 19:19:33 +0000 (19:19 +0000)
committerhunt <hunt>
Thu, 1 Nov 2007 19:19:33 +0000 (19:19 +0000)
* procfs.c, control.c, transport.c: Recognize when stapio
is detached and disable delayed work. Enable when attached.
Cleanup code to destroy workqueue on exit.

runtime/transport/ChangeLog
runtime/transport/control.c
runtime/transport/procfs.c
runtime/transport/transport.c
runtime/transport/transport.h

index 668113762b87a1aeddbc6fac0cb7488d5ce62d37..4872fa11635a336a22793e9bc1da8ec051960d0b 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-01  Martin Hunt  <hunt@redhat.com>
+
+       * procfs.c, control.c, transport.c: Recognize when stapio 
+       is detached and disable delayed work. Enable when attached.
+       Cleanup code to destroy workqueue on exit.
+
 2007-10-12  Martin Hunt  <hunt@redhat.com>
 
        * transport.c (_stp_ask_for_symbols): Don't ask for
index ae73165960483d9828ffade4b4f7024e022a1370..7846572a41f464e321ba9652af5769b6f62f0707 100644 (file)
@@ -261,6 +261,8 @@ static int _stp_ctl_send (int type, void *data, int len)
        } else {
                while ((err = _stp_ctl_write(type, data, len)) < 0 && trylimit--)
                        msleep (5);
+               if (err > 0)
+                       wake_up_interruptible(&_stp_ctl_wq);
        }
        kbug("returning %d\n", err);
        return err;
@@ -368,26 +370,19 @@ static int _stp_sym_close_cmd (struct inode *inode, struct file *file)
        return 0;
 }
 
-static int _stp_ctl_opens = 0;
 static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
 {
-       /* only allow one reader */
-       if (_stp_ctl_opens)
+       if (_stp_attached)
                return -1;
 
-       _stp_ctl_opens++;
-       _stp_pid = current->pid;
-       utt_overwrite_flag = 0;
+       _stp_attach();
        return 0;
 }
 
 static int _stp_ctl_close_cmd (struct inode *inode, struct file *file)
 {
-       if (_stp_ctl_opens)
-               _stp_ctl_opens--;
-       _stp_pid = 0;
-       if (!_stp_exit_flag)
-               utt_overwrite_flag = 1;
+       if (_stp_attached)
+               _stp_detach();
        return 0;
 }
 
index 887408470318858a1f1f7488d29c237eec0abe36..069e379ee93b80290dff743770505e7900bdf2c0 100644 (file)
@@ -324,6 +324,8 @@ static int _stp_ctl_send (int type, void *data, int len)
        } else {
                while ((err = _stp_ctl_write(type, data, len)) < 0 && trylimit--)
                        msleep (5);
+               if (err > 0)
+                       wake_up_interruptible(&_stp_ctl_wq);
        }
        return err;
 }
@@ -430,23 +432,19 @@ static int _stp_sym_close_cmd (struct inode *inode, struct file *file)
        return 0;
 }
 
-static int _stp_ctl_opens = 0;
 static int _stp_ctl_open_cmd (struct inode *inode, struct file *file)
 {
-       /* only allow one reader */
-       if (_stp_ctl_opens)
+       if (_stp_attached)
                return -1;
 
-       _stp_ctl_opens++;
-       _stp_pid = current->pid;
+       _stp_attach();
        return 0;
 }
 
 static int _stp_ctl_close_cmd (struct inode *inode, struct file *file)
 {
-       if (_stp_ctl_opens)
-               _stp_ctl_opens--;
-       _stp_pid = 0;
+       if (_stp_attached)
+               _stp_detach();
        return 0;
 }
 
index d44d6851e038f5a3c21e47e5da9123310c69b060..0a959917ca3f8b6e7093f98d302c7f824f1c1d45 100644 (file)
@@ -47,7 +47,8 @@ void probe_exit(void);
 int probe_start(void);
 void _stp_exit(void);
 void _stp_handle_start (struct _stp_msg_start *st);
-
+static void _stp_detach(void);
+static void _stp_attach(void);
 
 /* check for new workqueue API */
 #ifdef DECLARE_DELAYED_WORK 
@@ -115,6 +116,7 @@ static void _stp_cleanup_and_exit (int dont_rmmod)
        if (!_stp_exit_called) {
                int failures;
 
+               _stp_exit_flag = 1;
                unregister_module_notifier(&_stp_module_load_nb);
 
                /* we only want to do this stuff once */
@@ -141,6 +143,34 @@ static void _stp_cleanup_and_exit (int dont_rmmod)
        }
 }
 
+/*
+ * Called when stapio closes the control channel.
+ */
+static void _stp_detach(void)
+{
+       kbug("detach\n");
+       _stp_attached = 0;
+       _stp_pid = 0;
+
+       if (!_stp_exit_flag)
+               utt_overwrite_flag = 1;
+
+       cancel_delayed_work(&_stp_work);
+       wake_up_interruptible(&_stp_ctl_wq);
+}
+
+/*
+ * Called when stapio opens the control channel.
+ */
+static void _stp_attach(void)
+{
+       kbug("attach\n");
+       _stp_attached = 1;
+       _stp_pid = current->pid;
+       utt_overwrite_flag = 0;
+       queue_delayed_work(_stp_wq, &_stp_work, STP_WORK_TIMER);
+}
+
 /*
  *     _stp_work_queue - periodically check for IO or exit
  *     This is run by a kernel thread and may sleep.
@@ -162,12 +192,9 @@ static void _stp_work_queue (void *data)
                wake_up_interruptible(&_stp_ctl_wq);
 
        /* if exit flag is set AND we have finished with probe_start() */
-       if (unlikely(_stp_exit_flag && _stp_start_finished)) {
+       if (unlikely(_stp_exit_flag && _stp_start_finished))
                _stp_cleanup_and_exit(0);
-               cancel_delayed_work(&_stp_work);
-               flush_workqueue(_stp_wq);
-               wake_up_interruptible(&_stp_ctl_wq);
-       } else
+       else if (likely(_stp_attached))
                queue_delayed_work(_stp_wq, &_stp_work, STP_WORK_TIMER);
 }
 
@@ -179,18 +206,14 @@ static void _stp_work_queue (void *data)
  */
 void _stp_transport_close()
 {
-       kbug("************** transport_close *************\n");
+       kbug("%d: ************** transport_close *************\n", current->pid);
        _stp_cleanup_and_exit(1);
-       cancel_delayed_work(&_stp_work);
        destroy_workqueue(_stp_wq);
-       wake_up_interruptible(&_stp_ctl_wq);
-       unregister_module_notifier(&_stp_module_load_nb);
        _stp_unregister_ctl_channel();
        if (_stp_utt) utt_trace_remove(_stp_utt);
        _stp_free_modules();
        _stp_kill_time();
        _stp_print_cleanup();   /* free print buffers */
-
        kbug("---- CLOSED ----\n");
 }
 
@@ -257,9 +280,7 @@ int _stp_transport_init(void)
        _stp_wq = create_workqueue("systemtap");
        if (!_stp_wq)
                goto err3;
-
-       queue_delayed_work(_stp_wq, &_stp_work, STP_WORK_TIMER);
-
+       
        /* request symbolic information */
        _stp_ask_for_symbols();
        return 0;
index 0a83001e7840fab9c23d7f2d1efcd7ab4ce0c1b7..6dc00d2b4d858e9411ee0e08a8c166678cd19745 100644 (file)
@@ -26,4 +26,5 @@ int _stp_pid = 0;
 uid_t _stp_uid = 0;
 gid_t _stp_gid = 0;
 pid_t _stp_init_pid = 0;
+int _stp_attached = 0;
 #endif /* _TRANSPORT_TRANSPORT_H_ */
This page took 0.038109 seconds and 5 git commands to generate.