Whamcloud - gitweb
LU-4270 test: fix sanity test_209
[fs/lustre-release.git] / libcfs / libcfs / tracefile.c
index 49acdf2..e15ec68 100644 (file)
@@ -55,7 +55,7 @@ static struct tracefiled_ctl trace_tctl;
 struct mutex cfs_trace_thread_mutex;
 static int thread_running = 0;
 
-cfs_atomic_t cfs_tage_allocated = CFS_ATOMIC_INIT(0);
+atomic_t cfs_tage_allocated = ATOMIC_INIT(0);
 
 static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
                                          struct cfs_trace_cpu_data *tcd);
@@ -72,7 +72,7 @@ static struct cfs_trace_page *cfs_tage_alloc(int gfp)
        struct cfs_trace_page *tage;
 
        /* My caller is trying to free memory */
-       if (!cfs_in_interrupt() && memory_pressure_get())
+       if (!in_interrupt() && memory_pressure_get())
                return NULL;
 
        /*
@@ -91,7 +91,7 @@ static struct cfs_trace_page *cfs_tage_alloc(int gfp)
        }
 
        tage->page = page;
-       cfs_atomic_inc(&cfs_tage_allocated);
+       atomic_inc(&cfs_tage_allocated);
        return tage;
 }
 
@@ -102,7 +102,7 @@ static void cfs_tage_free(struct cfs_trace_page *tage)
 
        __free_page(tage->page);
        kfree(tage);
-       cfs_atomic_dec(&cfs_tage_allocated);
+       atomic_dec(&cfs_tage_allocated);
 }
 
 static void cfs_tage_to_tail(struct cfs_trace_page *tage,
@@ -157,7 +157,7 @@ cfs_trace_get_tage_try(struct cfs_trace_cpu_data *tcd, unsigned long len)
                        tage = cfs_tage_alloc(GFP_ATOMIC);
                        if (unlikely(tage == NULL)) {
                                if ((!memory_pressure_get() ||
-                                    cfs_in_interrupt()) && printk_ratelimit())
+                                    in_interrupt()) && printk_ratelimit())
                                        printk(KERN_WARNING
                                               "cannot allocate a tage (%ld)\n",
                                               tcd->tcd_cur_pages);
@@ -171,14 +171,14 @@ cfs_trace_get_tage_try(struct cfs_trace_cpu_data *tcd, unsigned long len)
                cfs_list_add_tail(&tage->linkage, &tcd->tcd_pages);
                tcd->tcd_cur_pages++;
 
-                if (tcd->tcd_cur_pages > 8 && thread_running) {
-                        struct tracefiled_ctl *tctl = &trace_tctl;
-                        /*
-                         * wake up tracefiled to process some pages.
-                         */
-                        cfs_waitq_signal(&tctl->tctl_waitq);
-                }
-                return tage;
+               if (tcd->tcd_cur_pages > 8 && thread_running) {
+                       struct tracefiled_ctl *tctl = &trace_tctl;
+                       /*
+                        * wake up tracefiled to process some pages.
+                        */
+                       wake_up(&tctl->tctl_waitq);
+               }
+               return tage;
         }
         return NULL;
 }
@@ -201,7 +201,6 @@ static void cfs_tcd_shrink(struct cfs_trace_cpu_data *tcd)
                       pgcount + 1, tcd->tcd_cur_pages);
 
         CFS_INIT_LIST_HEAD(&pc.pc_pages);
-       spin_lock_init(&pc.pc_lock);
 
         cfs_list_for_each_entry_safe_typed(tage, tmp, &tcd->tcd_pages,
                                            struct cfs_trace_page, linkage) {
@@ -488,7 +487,7 @@ cfs_trace_assertion_failed(const char *str,
 
        libcfs_panic_in_progress = 1;
        libcfs_catastrophe = 1;
-       cfs_mb();
+       smp_mb();
 
        cfs_set_ptldebug_header(&hdr, msgdata, CDEBUG_STACK());
 
@@ -529,7 +528,6 @@ static void collect_pages_on_all_cpus(struct page_collection *pc)
        struct cfs_trace_cpu_data *tcd;
        int i, cpu;
 
-       spin_lock(&pc->pc_lock);
         cfs_for_each_possible_cpu(cpu) {
                 cfs_tcd_for_each_type_lock(tcd, i, cpu) {
                         cfs_list_splice_init(&tcd->tcd_pages, &pc->pc_pages);
@@ -541,7 +539,6 @@ static void collect_pages_on_all_cpus(struct page_collection *pc)
                         }
                 }
         }
-       spin_unlock(&pc->pc_lock);
 }
 
 static void collect_pages(struct page_collection *pc)
@@ -562,7 +559,6 @@ static void put_pages_back_on_all_cpus(struct page_collection *pc)
         struct cfs_trace_page *tmp;
         int i, cpu;
 
-       spin_lock(&pc->pc_lock);
         cfs_for_each_possible_cpu(cpu) {
                 cfs_tcd_for_each_type_lock(tcd, i, cpu) {
                         cur_head = tcd->tcd_pages.next;
@@ -582,7 +578,6 @@ static void put_pages_back_on_all_cpus(struct page_collection *pc)
                         }
                 }
         }
-       spin_unlock(&pc->pc_lock);
 }
 
 static void put_pages_back(struct page_collection *pc)
@@ -601,7 +596,6 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
        struct cfs_trace_page *tage;
        struct cfs_trace_page *tmp;
 
-       spin_lock(&pc->pc_lock);
         cfs_list_for_each_entry_safe_typed(tage, tmp, &pc->pc_pages,
                                            struct cfs_trace_page, linkage) {
 
@@ -626,7 +620,6 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
                         tcd->tcd_cur_daemon_pages--;
                 }
         }
-       spin_unlock(&pc->pc_lock);
 }
 
 static void put_pages_on_daemon_list(struct page_collection *pc)
@@ -646,8 +639,6 @@ void cfs_trace_debug_print(void)
        struct cfs_trace_page *tage;
        struct cfs_trace_page *tmp;
 
-       spin_lock_init(&pc.pc_lock);
-
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
         cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
@@ -701,7 +692,6 @@ int cfs_tracefile_dump_all_pages(char *filename)
                goto out;
        }
 
-       spin_lock_init(&pc.pc_lock);
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
         if (cfs_list_empty(&pc.pc_pages)) {
@@ -746,8 +736,6 @@ void cfs_trace_flush_pages(void)
        struct cfs_trace_page *tage;
        struct cfs_trace_page *tmp;
 
-       spin_lock_init(&pc.pc_lock);
-
         pc.pc_want_daemon_pages = 1;
         collect_pages(&pc);
         cfs_list_for_each_entry_safe_typed(tage, tmp, &pc.pc_pages,
@@ -993,11 +981,10 @@ static int tracefiled(void *arg)
        /* we're started late enough that we pick up init's fs context */
        /* this is so broken in uml?  what on earth is going on? */
 
-       spin_lock_init(&pc.pc_lock);
        complete(&tctl->tctl_start);
 
-        while (1) {
-                cfs_waitlink_t __wait;
+       while (1) {
+               wait_queue_t __wait;
 
                 pc.pc_want_daemon_pages = 0;
                 collect_pages(&pc);
@@ -1072,23 +1059,23 @@ static int tracefiled(void *arg)
                                       "%d\n", ++i, tage->cpu);
                        printk(KERN_ERR "There are %d pages unwritten\n",
                               i);
-                }
-                __LASSERT(cfs_list_empty(&pc.pc_pages));
+               }
+               __LASSERT(cfs_list_empty(&pc.pc_pages));
 end_loop:
-                if (cfs_atomic_read(&tctl->tctl_shutdown)) {
-                        if (last_loop == 0) {
-                                last_loop = 1;
-                                continue;
-                        } else {
-                                break;
-                        }
-                }
-                cfs_waitlink_init(&__wait);
-                cfs_waitq_add(&tctl->tctl_waitq, &__wait);
-                cfs_set_current_state(CFS_TASK_INTERRUPTIBLE);
-                cfs_waitq_timedwait(&__wait, CFS_TASK_INTERRUPTIBLE,
-                                    cfs_time_seconds(1));
-                cfs_waitq_del(&tctl->tctl_waitq, &__wait);
+               if (atomic_read(&tctl->tctl_shutdown)) {
+                       if (last_loop == 0) {
+                               last_loop = 1;
+                               continue;
+                       } else {
+                               break;
+                       }
+               }
+               init_waitqueue_entry_current(&__wait);
+               add_wait_queue(&tctl->tctl_waitq, &__wait);
+               set_current_state(TASK_INTERRUPTIBLE);
+               waitq_timedwait(&__wait, TASK_INTERRUPTIBLE,
+                               cfs_time_seconds(1));
+               remove_wait_queue(&tctl->tctl_waitq, &__wait);
         }
        complete(&tctl->tctl_stop);
         return 0;
@@ -1105,8 +1092,8 @@ int cfs_trace_start_thread(void)
 
        init_completion(&tctl->tctl_start);
        init_completion(&tctl->tctl_stop);
-       cfs_waitq_init(&tctl->tctl_waitq);
-       cfs_atomic_set(&tctl->tctl_shutdown, 0);
+       init_waitqueue_head(&tctl->tctl_waitq);
+       atomic_set(&tctl->tctl_shutdown, 0);
 
        if (IS_ERR(kthread_run(tracefiled, tctl, "ktracefiled"))) {
                rc = -ECHILD;
@@ -1128,7 +1115,7 @@ void cfs_trace_stop_thread(void)
        if (thread_running) {
                printk(KERN_INFO
                       "Lustre: shutting down debug daemon thread...\n");
-               cfs_atomic_set(&tctl->tctl_shutdown, 1);
+               atomic_set(&tctl->tctl_shutdown, 1);
                wait_for_completion(&tctl->tctl_stop);
                thread_running = 0;
        }
@@ -1195,7 +1182,6 @@ static void cfs_trace_cleanup(void)
        struct page_collection pc;
 
        CFS_INIT_LIST_HEAD(&pc.pc_pages);
-       spin_lock_init(&pc.pc_lock);
 
        trace_cleanup_on_all_cpus();