blktrace 1.1.0
[blktrace.git] / btt / inlines.h
index 38ac5ef15ce32d2bf37d7b2bd00fbe2f555f295f..64b5a2c2244f50dc293c15350c9677112cb0e7b4 100644 (file)
  *
  */
 
-static inline struct range_info *new_cur(__u64 time)
+static inline int remapper_dev(__u32 dev)
 {
-       struct range_info *cur = malloc(sizeof(struct range_info));
+       int mjr = MAJOR(dev);
+       return mjr == 9 || mjr == 253 || mjr == 254;
+}
 
-       INIT_LIST_HEAD(&cur->head);
-       cur->start = time;
-       return cur;
+static inline void region_init(struct region_info *reg)
+{
+       INIT_LIST_HEAD(&reg->qranges);
+       INIT_LIST_HEAD(&reg->cranges);
 }
 
-static inline void update_range(struct list_head *head_p,
-                               struct range_info **cur_p, __u64 time)
+static inline void __region_exit(struct list_head *range_head)
 {
-       if (*cur_p == NULL)
-               *cur_p = new_cur(time);
-       else {
-               __u64 my_delta = (time > (*cur_p)->end) ? time - (*cur_p)->end : 1;
-               if (BIT_TIME(my_delta) >= range_delta) {
-                       list_add_tail(&(*cur_p)->head, head_p);
-                       *cur_p = new_cur(time);
-               }
+       struct list_head *p, *q;
+       struct range_info *rip;
+
+       list_for_each_safe(p, q, range_head) {
+               rip = list_entry(p, struct range_info, head);
+               free(rip);
        }
+}
 
-       (*cur_p)->end = time;
+static inline void region_exit(struct region_info *reg)
+{
+       __region_exit(&reg->qranges);
+       __region_exit(&reg->cranges);
 }
 
-static inline void init_region(struct region_info *reg)
+static inline void update_range(struct list_head *head_p, __u64 time)
 {
-       INIT_LIST_HEAD(&reg->qranges);
-       INIT_LIST_HEAD(&reg->cranges);
-       reg->qr_cur = reg->cr_cur = NULL;
+       struct range_info *rip;
+
+       if (!list_empty(head_p)) {
+               rip = list_entry(head_p->prev, struct range_info, head);
+
+               if (time < rip->end)
+                       return;
+
+               if (BIT_TIME(time - rip->end) < range_delta) {
+                       rip->end = time;
+                       return;
+               }
+       }
+
+       rip = malloc(sizeof(*rip));
+       rip->start = rip->end = time;
+       list_add_tail(&rip->head, head_p);
 }
 
 static inline void update_qregion(struct region_info *reg, __u64 time)
 {
-       update_range(&reg->qranges, &reg->qr_cur, time);
+       update_range(&reg->qranges, time);
 }
 
 static inline void update_cregion(struct region_info *reg, __u64 time)
 {
-       update_range(&reg->cranges, &reg->cr_cur, time);
+       update_range(&reg->cranges, time);
 }
 
 static inline void avg_update(struct avg_info *ap, __u64 t)
@@ -79,8 +97,7 @@ static inline void avg_update_n(struct avg_info *ap, __u64 t, int n)
         if (ap->n == 0) {
                 ap->min = ap->max = t;
                ap->total = (n * t);
-       }
-        else {
+       } else {
                 if (t < ap->min)
                         ap->min = t;
                 else if (t > ap->max)
@@ -106,65 +123,44 @@ static inline void update_lq(__u64 *last_q, struct avg_info *avg, __u64 time)
 
 static inline void dip_update_q(struct d_info *dip, struct io *iop)
 {
-       update_lq(&dip->last_q, &dip->avgs.q2q, iop->t.time);
+       if (remapper_dev(dip->device))
+               update_lq(&dip->last_q, &dip->avgs.q2q_dm, iop->t.time);
+       else
+               update_lq(&dip->last_q, &dip->avgs.q2q, iop->t.time);
        update_qregion(&dip->regions, iop->t.time);
 }
 
 static inline struct io *io_alloc(void)
 {
-       struct io *iop;
-
-       if (!list_empty(&free_ios)) {
-               iop = list_entry(free_ios.next, struct io, f_head);
-               LIST_DEL(&iop->f_head);
-
-#              if defined(COUNT_IOS)
-                       nios_reused++;
-#              endif
-       }
-       else {
-               iop = malloc(sizeof(struct io));
-
-#              if defined(COUNT_IOS)
-                       nios_alloced++;
-#              endif
-       }
+       struct io *iop = malloc(sizeof(*iop));
 
        memset(iop, 0, sizeof(struct io));
-       INIT_LIST_HEAD(&iop->down_list);
-       INIT_LIST_HEAD(&iop->up_list);
-
-#      if defined(DEBUG)
-               iop->f_head.next = LIST_POISON1;
-               iop->c_pending.next = LIST_POISON1;
-               iop->retry.next = LIST_POISON1;
-#      endif
-
-#      if defined(COUNT_IOS)
-               list_add_tail(&iop->cio_head, &cios);
-#      endif
+       list_add_tail(&iop->a_head, &all_ios);
 
        return iop;
 }
 
 static inline void io_free(struct io *iop)
 {
-#      if defined(COUNT_IOS)
-               nios_freed++;
-               LIST_DEL(&iop->cio_head);
-#      endif
+       list_del(&iop->a_head);
+       free(iop);
+}
 
-#      if defined(DEBUG)
-               memset(iop, 0, sizeof(*iop));
-#      endif
+static inline void io_free_all(void)
+{
+       struct io *iop;
+       struct list_head *p, *q;
 
-       list_add_tail(&iop->f_head, &free_ios);
+       list_for_each_safe(p, q, &all_ios) {
+               iop = list_entry(p, struct io, a_head);
+               free(iop);
+       }
 }
 
 static inline int io_setup(struct io *iop, enum iop_type type)
 {
        iop->type = type;
-       iop->dip = dip_add(iop->t.device, iop);
+       iop->dip = dip_alloc(iop->t.device, iop);
        if (iop->linked) {
                iop->pip = find_process(iop->t.pid, NULL);
                iop->bytes_left = iop->t.bytes;
@@ -175,15 +171,9 @@ static inline int io_setup(struct io *iop, enum iop_type type)
 
 static inline void io_release(struct io *iop)
 {
-       ASSERT(iop->f_head.next == LIST_POISON1);
-       ASSERT(iop->c_pending.next == LIST_POISON1);
-       ASSERT(iop->retry.next == LIST_POISON1);
-       ASSERT(list_empty(&iop->up_list));
-       ASSERT(list_empty(&iop->down_list));
-
        if (iop->linked)
-               dip_rem(iop);
-       if (iop->pdu) 
+               iop_rem_dip(iop);
+       if (iop->pdu)
                free(iop->pdu);
 
        io_free(iop);
@@ -209,44 +199,57 @@ static inline void io_release(struct io *iop)
 
 static inline void update_q2c(struct io *iop, __u64 c_time)
 {
-#      if defined(DEBUG)
-               if (per_io_ofp) 
-                       fprintf(per_io_ofp, "q2c %13.9f\n", BIT_TIME(c_time));
-#      endif
-       UPDATE_AVGS(q2c, iop, iop->pip, c_time);
+       if (remapper_dev(iop->dip->device))
+               UPDATE_AVGS(q2c_dm, iop, iop->pip, c_time);
+       else
+               UPDATE_AVGS(q2c, iop, iop->pip, c_time);
 }
 
 static inline void update_q2a(struct io *iop, __u64 a_time)
 {
-#      if defined(DEBUG)
-               if (per_io_ofp) 
-                       fprintf(per_io_ofp, "q2a %13.9f\n", BIT_TIME(a_time));
-#      endif
-       UPDATE_AVGS(q2a, iop, iop->pip, a_time);
+       if (remapper_dev(iop->dip->device))
+               UPDATE_AVGS(q2a_dm, iop, iop->pip, a_time);
+       else
+               UPDATE_AVGS(q2a, iop, iop->pip, a_time);
 }
 
-static inline void update_q2i(struct io *iop, __u64 i_time)
+static inline void update_q2g(struct io *iop, __u64 g_time)
 {
-#      if defined(DEBUG)
-               if (per_io_ofp) 
-                       fprintf(per_io_ofp, "q2i %13.9f\n", BIT_TIME(i_time));
-#      endif
+       UPDATE_AVGS(q2g, iop, iop->pip, g_time);
+}
 
-       UPDATE_AVGS(q2i, iop, iop->pip, i_time);
+static inline void update_s2g(struct io *iop, __u64 g_time)
+{
+       UPDATE_AVGS(s2g, iop, iop->pip, g_time);
 }
 
-static inline void unupdate_q2i(struct io *iop, __u64 i_time)
+static inline void unupdate_q2g(struct io *iop, __u64 g_time)
 {
-       UNUPDATE_AVGS(q2i, iop, iop->pip, i_time);
+       UNUPDATE_AVGS(q2g, iop, iop->pip, g_time);
 }
 
-static inline void update_i2d(struct io *iop, __u64 d_time)
+static inline void update_g2i(struct io *iop, __u64 i_time)
 {
-#      if defined(DEBUG)
-               if (per_io_ofp) 
-                       fprintf(per_io_ofp, "i2d %13.9f\n", BIT_TIME(d_time));
-#      endif
+       UPDATE_AVGS(g2i, iop, iop->pip, i_time);
+}
+
+static inline void unupdate_g2i(struct io *iop, __u64 i_time)
+{
+       UNUPDATE_AVGS(g2i, iop, iop->pip, i_time);
+}
 
+static inline void update_q2m(struct io *iop, __u64 m_time)
+{
+       UPDATE_AVGS(q2m, iop, iop->pip, m_time);
+}
+
+static inline void unupdate_q2m(struct io *iop, __u64 m_time)
+{
+       UNUPDATE_AVGS(q2m, iop, iop->pip, m_time);
+}
+
+static inline void update_i2d(struct io *iop, __u64 d_time)
+{
        UPDATE_AVGS(i2d, iop, iop->pip, d_time);
 }
 
@@ -255,22 +258,25 @@ static inline void unupdate_i2d(struct io *iop, __u64 d_time)
        UNUPDATE_AVGS(i2d, iop, iop->pip, d_time);
 }
 
-static inline void update_d2c(struct io *iop, int n, __u64 c_time)
+static inline void update_m2d(struct io *iop, __u64 d_time)
 {
-#      if defined(DEBUG)
-               if (per_io_ofp) 
-                       fprintf(per_io_ofp, "d2c %13.9f\n", 
-                                                       n*BIT_TIME(c_time));
-#      endif
+       UPDATE_AVGS(m2d, iop, iop->pip, d_time);
+}
 
-       UPDATE_AVGS_N(d2c, iop, iop->pip, c_time, n);
+static inline void unupdate_m2d(struct io *iop, __u64 d_time)
+{
+       UNUPDATE_AVGS(m2d, iop, iop->pip, d_time);
+}
+
+static inline void update_d2c(struct io *iop, __u64 c_time)
+{
+       UPDATE_AVGS(d2c, iop, iop->pip, c_time);
 }
 
 static inline void update_blks(struct io *iop)
 {
        __u64 nblks = iop->t.bytes >> 9;
        avg_update(&all_avgs.blks, nblks);
-       ASSERT(iop->dip != NULL);
        avg_update(&iop->dip->avgs.blks, nblks);
        if (iop->pip)
                avg_update(&iop->pip->avgs.blks, nblks);
@@ -282,12 +288,6 @@ static inline struct rb_root *__get_root(struct d_info *dip, enum iop_type type)
        return &roots[type];
 }
 
-static inline void *dip_rb_mkhds(void)
-{
-       size_t len = N_IOP_TYPES * sizeof(struct rb_root);
-       return memset(malloc(len), 0, len);
-}
-
 static inline int dip_rb_ins(struct d_info *dip, struct io *iop)
 {
        return rb_insert(__get_root(dip, iop->type), iop);
@@ -296,75 +296,25 @@ static inline int dip_rb_ins(struct d_info *dip, struct io *iop)
 static inline void dip_rb_rem(struct io *iop)
 {
        rb_erase(&iop->rb_node, __get_root(iop->dip, iop->type));
-
-#      if defined(DEBUG)
-               rb_tree_size--;
-#      endif
 }
 
-static inline void dip_rb_fe(struct d_info *dip, enum iop_type type, 
-                            struct io *iop, 
-                            void (*fnc)(struct io *iop, struct io *this), 
+static inline void dip_rb_fe(struct d_info *dip, enum iop_type type,
+                            struct io *iop,
+                            void (*fnc)(struct io *iop, struct io *this),
                             struct list_head *head)
 {
        rb_foreach(__get_root(dip, type)->rb_node, iop, fnc, head);
 }
 
-static inline struct io *dip_rb_find_sec(struct d_info *dip, 
+static inline struct io *dip_rb_find_sec(struct d_info *dip,
                                         enum iop_type type, __u64 sec)
 {
        return rb_find_sec(__get_root(dip, type), sec);
 }
 
-static inline void bump_retry(__u64 now)
-{
-       if (!list_empty(&retries))
-               next_retry_check = now + (100 * 1000); // 100 usec
-       else 
-               next_retry_check = 0;
-}
-
-static inline void add_retry(struct io *iop)
-{
-       bump_retry(iop->t.time);
-       if (!iop->on_retry_list) {
-               list_add_tail(&iop->retry, &retries);
-               iop->on_retry_list = 1;
-       }
-}
-
-static inline void del_retry(struct io *iop)
-{
-       if (iop->on_retry_list) {
-               LIST_DEL(&iop->retry);
-               iop->on_retry_list = 0;
-       }
-       bump_retry(iop->t.time);
-}
-
-static inline __u64 tdelta(struct io *iop1, struct io *iop2)
-{
-       __u64 t1 = iop1->t.time;
-       __u64 t2 = iop2->t.time;
-       return (t1 < t2) ? (t2 - t1) : 1;
-}
-
-static inline int remapper_dev(__u32 dev)
+static inline __u64 tdelta(__u64 from, __u64 to)
 {
-       int mjr = MAJOR(dev);
-       return mjr == 9 || mjr == 253 || mjr == 254;
-}
-
-static inline void dump_iop(struct io *iop, int extra_nl)
-{
-       if (per_io_ofp) 
-               __dump_iop(per_io_ofp, iop, extra_nl);
-}
-
-static inline void dump_iop2(struct io *a_iop, struct io *l_iop)
-{
-       if (per_io_ofp) 
-               __dump_iop2(per_io_ofp, a_iop, l_iop);
+       return (from < to) ? (to - from) : 1;
 }
 
 static inline int type2c(enum iop_type type)
@@ -380,111 +330,54 @@ static inline int type2c(enum iop_type type)
        case IOP_D: c = 'D'; break;
        case IOP_C: c = 'C'; break;
        case IOP_R: c = 'R'; break;
-       case IOP_L: c = 'L'; break;
+       case IOP_G: c = 'G'; break;
        default   : c = '?'; break;
        }
 
        return c;
 }
 
-static inline void bilink_free(struct bilink *blp)
-{
-       free(blp);
-}
-
-static inline struct bilink *bilink_alloc(struct io *diop, struct io *uiop)
-{
-       struct bilink *blp = malloc(sizeof(*blp));
-
-       blp->diop = diop;
-       blp->uiop = uiop;
-
-       return blp;
-}
-
-static inline void bilink(struct io *diop, struct io *uiop)
+static inline int histo_idx(__u64 nbytes)
 {
-       struct bilink *blp = bilink_alloc(diop, uiop);
-
-       list_add_tail(&blp->down_head, &diop->up_list);
-       list_add_tail(&blp->up_head, &uiop->down_list);
-
-       diop->up_len++;
-       uiop->down_len++;
+       int idx = (nbytes >> 9) - 1;
+       return min(idx, N_HIST_BKTS-1);
 }
 
-static inline void biunlink(struct bilink *blp)
+static inline void update_q_histo(__u64 nbytes)
 {
-       LIST_DEL(&blp->down_head);
-       LIST_DEL(&blp->up_head);
-       blp->diop->up_len--;
-       blp->uiop->down_len--;
-       bilink_free(blp);
+       q_histo[histo_idx(nbytes)]++;
 }
 
-static inline struct io *bilink_first_down(struct io *iop, 
-                                                       struct bilink **blp_p)
+static inline void update_d_histo(__u64 nbytes)
 {
-       struct bilink *blp;
-
-       if (list_empty(&iop->down_list))
-               return NULL;
-       blp = list_entry(iop->down_list.next, struct bilink, up_head);
-
-       if (blp_p != NULL) 
-               *blp_p = blp;
-       return blp->diop;
+       d_histo[histo_idx(nbytes)]++;
 }
 
-static inline struct io *bilink_first_up(struct io *iop, struct bilink **blp_p)
+static inline struct io *io_first_list(struct list_head *head)
 {
-       struct bilink *blp;
-
-       if (list_empty(&iop->up_list))
+       if (list_empty(head))
                return NULL;
-       blp = list_entry(iop->up_list.next, struct bilink, down_head);
 
-       if (blp_p != NULL) 
-               *blp_p = blp;
-       return blp->uiop;
+       return list_entry(head->next, struct io, f_head);
 }
 
-typedef void (*bilink_func)(struct io *diop, struct io *uiop, 
-                                                       struct io *c_iop);
-static inline void bilink_for_each_down(bilink_func func, struct io *uiop,
-                                       struct io *c_iop, int ul)
+static inline void __dump_iop(FILE *ofp, struct io *iop, int extra_nl)
 {
-       struct bilink *blp;
-       struct list_head *p, *q;
-
-       list_for_each_safe(p, q, &uiop->down_list) {
-               blp = list_entry(p, struct bilink, up_head);
-               func(blp->diop, uiop, c_iop);
-               if (ul)
-                       biunlink(blp);
-       }
+       fprintf(ofp, "%5d.%09lu %3d,%-3d %c %10llu+%-4u\n",
+               (int)SECONDS(iop->t.time),
+               (unsigned long)NANO_SECONDS(iop->t.time),
+               MAJOR(iop->t.device), MINOR(iop->t.device), type2c(iop->type),
+               (unsigned long long)iop->t.sector, t_sec(&iop->t));
+       if (extra_nl) fprintf(ofp, "\n");
 }
 
-static inline int histo_idx(__u64 nbytes)
+static inline void __dump_iop2(FILE *ofp, struct io *a_iop, struct io *l_iop)
 {
-       int idx = (nbytes >> 9) - 1;
-       return min(idx, N_HIST_BKTS-1);
-}
-
-static inline void update_q_histo(__u64 nbytes)
-{
-       q_histo[histo_idx(nbytes)]++;
-}
-
-static inline void update_d_histo(__u64 nbytes)
-{
-       d_histo[histo_idx(nbytes)]++;
-}
-
-static inline void add_rmhd(struct io *iop)
-{
-       if (!iop->on_rm_list) {
-               list_add_tail(&iop->rm_head, &rmhd);
-               iop->on_rm_list = 1;
-       }
+       fprintf(ofp, "%5d.%09lu %3d,%-3d %c %10llu+%-4u <- (%3d,%-3d) %10llu\n",
+               (int)SECONDS(a_iop->t.time),
+               (unsigned long)NANO_SECONDS(a_iop->t.time),
+               MAJOR(a_iop->t.device), MINOR(a_iop->t.device),
+               type2c(a_iop->type), (unsigned long long)a_iop->t.sector,
+               t_sec(&a_iop->t), MAJOR(l_iop->t.device),
+               MINOR(l_iop->t.device), (unsigned long long)l_iop->t.sector);
 }