Merge branch 'vendor/OPENSSL'
[dragonfly.git] / sys / kern / kern_ktr.c
index 9506906..238762e 100644 (file)
@@ -117,11 +117,11 @@ KTR_INFO(KTR_TESTLOG, testlog, test6, 5, "test6", 0);
 #ifdef SMP
 KTR_INFO(KTR_TESTLOG, testlog, pingpong, 6, "pingpong", 0);
 KTR_INFO(KTR_TESTLOG, testlog, pipeline, 7, "pipeline", 0);
-#endif
 KTR_INFO(KTR_TESTLOG, testlog, crit_beg, 8, "crit_beg", 0);
 KTR_INFO(KTR_TESTLOG, testlog, crit_end, 9, "crit_end", 0);
 KTR_INFO(KTR_TESTLOG, testlog, spin_beg, 10, "spin_beg", 0);
 KTR_INFO(KTR_TESTLOG, testlog, spin_end, 11, "spin_end", 0);
+#endif
 #define logtest(name)  KTR_LOG(testlog_ ## name, 0, 0, 0, 0)
 #define logtest_noargs(name)   KTR_LOG(testlog_ ## name)
 #endif
@@ -146,7 +146,9 @@ SYSCTL_INT(_debug_ktr, OID_AUTO, resynchronize, CTLFLAG_RW, &ktr_resynchronize,
 static int     ktr_testlogcnt = 0;
 SYSCTL_INT(_debug_ktr, OID_AUTO, testlogcnt, CTLFLAG_RW, &ktr_testlogcnt, 0, "");
 static int     ktr_testipicnt = 0;
+#ifdef SMP
 static int     ktr_testipicnt_remainder;
+#endif
 SYSCTL_INT(_debug_ktr, OID_AUTO, testipicnt, CTLFLAG_RW, &ktr_testipicnt, 0, "");
 static int     ktr_testcritcnt = 0;
 SYSCTL_INT(_debug_ktr, OID_AUTO, testcritcnt, CTLFLAG_RW, &ktr_testcritcnt, 0, "");
@@ -159,8 +161,11 @@ SYSCTL_INT(_debug_ktr, OID_AUTO, testspincnt, CTLFLAG_RW, &ktr_testspincnt, 0, "
  * early boot (note however that we still use a critical section, XXX).
  */
 static struct  ktr_entry ktr_buf0[KTR_ENTRIES];
-struct         ktr_entry *ktr_buf[MAXCPU] = { &ktr_buf0[0] };
-int            ktr_idx[MAXCPU];
+
+__cachealign struct ktr_cpu ktr_cpu[MAXCPU] = {
+       { .core.ktr_buf = &ktr_buf0[0] }
+};
+
 #ifdef SMP
 static int     ktr_sync_state = 0;
 static int     ktr_sync_count;
@@ -181,11 +186,13 @@ extern int64_t tsc_offsets[];
 static void
 ktr_sysinit(void *dummy)
 {
+       struct ktr_cpu_core *kcpu;
        int i;
 
        for(i = 1; i < ncpus; ++i) {
-               ktr_buf[i] = kmalloc(KTR_ENTRIES * sizeof(struct ktr_entry),
-                                   M_KTR, M_WAITOK | M_ZERO);
+               kcpu = &ktr_cpu[i].core;
+               kcpu->ktr_buf = kmalloc(KTR_ENTRIES * sizeof(struct ktr_entry),
+                                       M_KTR, M_WAITOK | M_ZERO);
        }
        callout_init(&ktr_resync_callout);
        callout_reset(&ktr_resync_callout, hz / 10, ktr_resync_callback, NULL);
@@ -202,9 +209,11 @@ SYSINIT(ktr_sysinit, SI_BOOT2_KLD, SI_ORDER_ANY, ktr_sysinit, NULL);
  * This callback occurs on cpu0.
  */
 #if KTR_TESTLOG
+#ifdef SMP
 static void ktr_pingpong_remote(void *dummy);
 static void ktr_pipeline_remote(void *dummy);
 #endif
+#endif
 
 #if defined(SMP) && defined(_RDTSC_SUPPORTED_)
 
@@ -271,18 +280,12 @@ ktr_resync_callback(void *dummy __unused)
                struct spinlock spin;
 
                spin_init(&spin);
-               spin_lock_wr(&spin);
-               spin_unlock_wr(&spin);
-               logtest_noargs(spin_beg);
-               for (count = ktr_testspincnt; count; --count) {
-                       spin_lock_wr(&spin);
-                       spin_unlock_wr(&spin);
-               }
-               logtest_noargs(spin_end);
+               spin_lock(&spin);
+               spin_unlock(&spin);
                logtest_noargs(spin_beg);
                for (count = ktr_testspincnt; count; --count) {
-                       spin_lock_rd(&spin);
-                       spin_unlock_rd(&spin);
+                       spin_lock(&spin);
+                       spin_unlock(&spin);
                }
                logtest_noargs(spin_end);
                ktr_testspincnt = 0;
@@ -436,16 +439,18 @@ static __inline
 void
 ktr_write_entry(struct ktr_info *info, const char *file, int line, __va_list va)
 {
+       struct ktr_cpu_core *kcpu;
        struct ktr_entry *entry;
        int cpu;
 
        cpu = mycpu->gd_cpuid;
-       if (!ktr_buf[cpu])
+       kcpu = &ktr_cpu[cpu].core;
+       if (kcpu->ktr_buf == NULL)
                return;
 
        crit_enter();
-       entry = ktr_buf[cpu] + (ktr_idx[cpu] & KTR_ENTRIES_MASK);
-       ++ktr_idx[cpu];
+       entry = kcpu->ktr_buf + (kcpu->ktr_idx & KTR_ENTRIES_MASK);
+       ++kcpu->ktr_idx;
 #ifdef _RDTSC_SUPPORTED_
        if (cpu_feature & CPUID_TSC) {
 #ifdef SMP
@@ -508,6 +513,7 @@ static      int db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx);
 
 DB_SHOW_COMMAND(ktr, db_ktr_all)
 {
+       struct ktr_cpu_core *kcpu;
        int a_flag = 0;
        int c;
        int nl = 0;
@@ -516,8 +522,9 @@ DB_SHOW_COMMAND(ktr, db_ktr_all)
        int printcpu = -1;
 
        for(i = 0; i < ncpus; i++) {
+               kcpu = &ktr_cpu[i].core;
                tstate[i].first = -1;
-               tstate[i].cur = ktr_idx[i] & KTR_ENTRIES_MASK;
+               tstate[i].cur = (kcpu->ktr_idx - 1) & KTR_ENTRIES_MASK;
        }
        db_ktr_verbose = 0;
        while ((c = *(modif++)) != '\0') {
@@ -564,7 +571,8 @@ DB_SHOW_COMMAND(ktr, db_ktr_all)
                 * Find the lowest timestamp
                 */
                for (i = 0, counter = 0; i < ncpus; i++) {
-                       if (ktr_buf[i] == NULL)
+                       kcpu = &ktr_cpu[i].core;
+                       if (kcpu->ktr_buf == NULL)
                                continue;
                        if (printcpu != -1 && printcpu != i)
                                continue;
@@ -576,14 +584,18 @@ DB_SHOW_COMMAND(ktr, db_ktr_all)
                                }
                                continue;
                        }
-                       if (ktr_buf[i][tstate[i].cur].ktr_timestamp > highest_ts) {
-                               highest_ts = ktr_buf[i][tstate[i].cur].ktr_timestamp;
+                       if (kcpu->ktr_buf[tstate[i].cur].ktr_timestamp > highest_ts) {
+                               highest_ts = kcpu->ktr_buf[tstate[i].cur].ktr_timestamp;
                                highest_cpu = i;
                        }
                }
+               if (highest_cpu < 0) {
+                       db_printf("no KTR data available\n");
+                       break;
+               }
                i = highest_cpu;
-               KKASSERT(i != -1);
-               kp = &ktr_buf[i][tstate[i].cur];
+               kcpu = &ktr_cpu[i].core;
+               kp = &kcpu->ktr_buf[tstate[i].cur];
                if (tstate[i].first == -1)
                        tstate[i].first = tstate[i].cur;
                if (--tstate[i].cur < 0)
@@ -593,7 +605,7 @@ DB_SHOW_COMMAND(ktr, db_ktr_all)
                        tstate[i].cur = -1;
                        continue;
                }
-               if (ktr_buf[i][tstate[i].cur].ktr_info == NULL)
+               if (kcpu->ktr_buf[tstate[i].cur].ktr_info == NULL)
                        tstate[i].cur = -1;
                if (db_more(&nl) == -1)
                        break;
@@ -617,8 +629,10 @@ db_mach_vtrace(int cpu, struct ktr_entry *kp, int idx)
        }
        db_printf("%s\t", kp->ktr_info->kf_name);
        db_printf("from(%p,%p) ", kp->ktr_caller1, kp->ktr_caller2);
+#ifdef __i386__
        if (kp->ktr_info->kf_format)
                db_vprintf(kp->ktr_info->kf_format, (__va_list)kp->ktr_data);
+#endif
        db_printf("\n");
 
        return(1);