void timer_init() { intr_handler_s th; th.callback = timer_cb; register_irq(TIMER_IRQ, &th); hz = get_hz(); tw_printf("hz is 0x%x\n", hz); // timer use ivt 0x20 lapic_write_reg(_LAPIC_TIMER_OFFSET, TIMER_IRQ); }
int process_token() { HZ hz_set[MAX_LENGTH]; int i; for (i = 0; i < max_length; i++) hz_set[i] = TERMINAL; do { for (i = min_length; i <= max_length; i++) output_correct_token(hz_set, i); for (i = 0; i < max_length - 1; i++) hz_set[i] = hz_set[i + 1]; hz_set[i] = get_hz(); }while(hz_set[0] != END); return 1; }
void dump(void){ int i; unsigned long long hz = get_hz(); int last_recv_pkt = -1; int total_pkts_dropped = npkts; float tput_mbs; timer_disable(); for (i=0; i<npkts; i++){ if (!suppress_dump) printf("%5u %llu %llu (%llu) %llu\n", udpdata[i].seq, udpdata[i].tsctx, udpdata[i].tscrx, udpdata[i].tscrx-udpdata[i].tsctx, (udpdata[i].tscrx-udpdata[i].tsctx)*1000000/hz); if(udpdata[i].tsctx != 0) { last_recv_pkt = i; --total_pkts_dropped; } } // Print throughput if (last_recv_pkt >= 0) { tput_mbs = (long long)(npkts - total_pkts_dropped) * bufsz / ((udpdata[last_recv_pkt].tscrx - udpdata[0].tsctx)*1.0/hz) / 1000000.0; } else { tput_mbs = 0.0; } fprintf(stderr, "Average throughput: %.0f MB/s = %.2f Gbit/s\n", tput_mbs, tput_mbs * 8 / 1000); // Print number of dropped packets fprintf(stderr, "Dropped packets: %d of %d (%.1f%%)\n", total_pkts_dropped, npkts, total_pkts_dropped*100.0 / npkts); }
int print_neigh(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct ndmsg *r = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[NDA_MAX+1]; char abuf[256]; if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH) { fprintf(stderr, "Not RTM_NEWNEIGH: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } len -= NLMSG_LENGTH(sizeof(*r)); if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (filter.flushb && n->nlmsg_type != RTM_NEWNEIGH) return 0; if (filter.family && filter.family != r->ndm_family) return 0; if (filter.index && filter.index != r->ndm_ifindex) return 0; if (!(filter.state&r->ndm_state) && (r->ndm_state || !(filter.state&0x100)) && (r->ndm_family != AF_DECnet)) return 0; memset(tb, 0, sizeof(tb)); parse_rtattr(tb, NDA_MAX, NDA_RTA(r), n->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); if (tb[NDA_DST]) { if (filter.pfx.family) { inet_prefix dst; memset(&dst, 0, sizeof(dst)); dst.family = r->ndm_family; memcpy(&dst.data, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) return 0; } } if (filter.unused_only && tb[NDA_CACHEINFO]) { struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); if (ci->ndm_refcnt) return 0; } if (filter.flushb) { struct nlmsghdr *fn; if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { if (flush_update()) return -1; } fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); memcpy(fn, n, n->nlmsg_len); fn->nlmsg_type = RTM_DELNEIGH; fn->nlmsg_flags = NLM_F_REQUEST; fn->nlmsg_seq = ++filter.rth->seq; filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; filter.flushed++; if (show_stats < 2) return 0; } if (tb[NDA_DST]) { fprintf(fp, "%s ", format_host(r->ndm_family, RTA_PAYLOAD(tb[NDA_DST]), RTA_DATA(tb[NDA_DST]), abuf, sizeof(abuf))); } if (!filter.index && r->ndm_ifindex) fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex)); if (tb[NDA_LLADDR]) { SPRINT_BUF(b1); fprintf(fp, "lladdr %s", ll_addr_n2a(RTA_DATA(tb[NDA_LLADDR]), RTA_PAYLOAD(tb[NDA_LLADDR]), ll_index_to_type(r->ndm_ifindex), b1, sizeof(b1))); } if (r->ndm_flags & NTF_ROUTER) { fprintf(fp, " router"); } if (tb[NDA_CACHEINFO] && show_stats) { static int hz; struct nda_cacheinfo *ci = RTA_DATA(tb[NDA_CACHEINFO]); if (!hz) hz = get_hz(); if (ci->ndm_refcnt) printf(" ref %d", ci->ndm_refcnt); fprintf(fp, " used %d/%d/%d", ci->ndm_used/hz, ci->ndm_confirmed/hz, ci->ndm_updated/hz); } if (r->ndm_state) { SPRINT_BUF(b1); fprintf(fp, " nud %s", nud_state_n2a(r->ndm_state, b1, sizeof(b1))); } fprintf(fp, "\n"); fflush(fp); return 0; }
int htb_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) { int ok=0; struct tc_htb_opt opt; __u32 * rtab = vmalloc(256*sizeof(__u32)); __u32 * ctab = vmalloc(256*sizeof(__u32)); unsigned buffer=0,cbuffer=0; int cell_log=-1,ccell_log = -1; unsigned mtu; unsigned short mpu = 0; unsigned short overhead = 0; unsigned int linklayer = LINKLAYER_ETHERNET; struct rtattr *tail; memset(&opt, 0, sizeof(opt)); mtu = 1600; while (argc > 0) { if (matches(*argv, "prio") == 0) { NEXT_ARG(); if (get_u32(&opt.prio, *argv, 10)) { explain1("prio"); return -1; } ok++; } else if (matches(*argv, "mtu") == 0) { NEXT_ARG(); if (get_u32(&mtu, *argv, 10)) { explain1("mtu"); return -1; } } else if (matches(*argv, "mpu") == 0) { NEXT_ARG(); if (get_u16(&mpu, *argv, 10)) { explain1("mpu"); return -1; } } else if (matches(*argv, "overhead") == 0) { NEXT_ARG(); if (get_u16(&overhead, *argv, 10)) { explain1("overhead"); return -1; } } else if (matches(*argv, "linklayer") == 0) { NEXT_ARG(); if (get_linklayer(&linklayer, *argv)) { explain1("linklayer"); return -1; } } else if (matches(*argv, "quantum") == 0) { NEXT_ARG(); if (get_u32(&opt.quantum, *argv, 10)) { explain1("quantum"); return -1; } } /* else if (matches(*argv, "burst") == 0 || strcmp(*argv, "buffer") == 0 || strcmp(*argv, "maxburst") == 0) { NEXT_ARG(); if (get_size_and_cell(&buffer, &cell_log, *argv) < 0) { explain1("buffer"); return -1; } ok++; } */ /* else if (matches(*argv, "cburst") == 0 || strcmp(*argv, "cbuffer") == 0 || strcmp(*argv, "cmaxburst") == 0) { NEXT_ARG(); if (get_size_and_cell(&cbuffer, &ccell_log, *argv) < 0) { explain1("cbuffer"); return -1; } ok++; } */ else if (strcmp(*argv, "ceil") == 0) { NEXT_ARG(); if (opt.ceil.rate) { printk(KERN_DEBUG "[MTC] [Q_HTB] Double \"ceil\" spec\n"); return -1; } if (get_rate(&opt.ceil.rate, *argv)) { explain1("ceil"); return -1; } ok++; } else if (strcmp(*argv, "rate") == 0) { NEXT_ARG(); if (opt.rate.rate) { printk(KERN_DEBUG "[MTC] [Q_HTB] Double \"rate\" spec\n"); return -1; } if (get_rate(&opt.rate.rate, *argv)) { explain1("rate"); return -1; } ok++; } else if (strcmp(*argv, "help") == 0) { return -1; } else { printk(KERN_DEBUG "[MTC] [Q_HTB] What is \"%s\"?\n", *argv); return -1; } argc--; argv++; } /* if (!ok) return 0;*/ if (opt.rate.rate == 0) { printk(KERN_DEBUG "[MTC] [Q_HTB] \"rate\" is required.\n"); return -1; } if (!opt.ceil.rate) opt.ceil = opt.rate; if (!buffer) buffer = opt.rate.rate / get_hz() + mtu; if (!cbuffer) cbuffer = opt.ceil.rate / get_hz() + mtu; opt.ceil.overhead = overhead; opt.rate.overhead = overhead; opt.ceil.mpu = mpu; opt.rate.mpu = mpu; if (tc_calc_rtable(&opt.rate, rtab, cell_log, mtu, linklayer) < 0) { printk(KERN_DEBUG "[MTC] [Q_HTB] error: failed to calculate rate table.\n"); return -1; } opt.buffer = tc_calc_xmittime(opt.rate.rate, buffer); if (tc_calc_rtable(&opt.ceil, ctab, ccell_log, mtu, linklayer) < 0) { printk(KERN_DEBUG "[MTC] [Q_HTB] error: failed to calculate ceil rate table.\n"); return -1; } opt.cbuffer = tc_calc_xmittime(opt.ceil.rate, cbuffer); tail = NLMSG_TAIL(n); addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); addattr_l(n, 2024, TCA_HTB_PARMS, &opt, sizeof(opt)); addattr_l(n, 3024, TCA_HTB_RTAB, rtab, 1024); addattr_l(n, 4024, TCA_HTB_CTAB, ctab, 1024); tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; return 0; }
int Clock_Ticks::get_usecs_per_tick (void) { return 1000000 / get_hz (); }
static int print_route(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; struct rtmsg *r = NLMSG_DATA(n); int len = n->nlmsg_len; struct rtattr * tb[RTA_MAX+1]; char abuf[256]; inet_prefix dst; inet_prefix src; int host_len = -1; SPRINT_BUF(b1); if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) { fprintf(stderr, "Not a route: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); return 0; } if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE) return 0; len -= NLMSG_LENGTH(sizeof(*r)); if (len < 0) { bb_error_msg("wrong nlmsg len %d", len); return -1; } if (r->rtm_family == AF_INET6) host_len = 128; else if (r->rtm_family == AF_INET) host_len = 32; if (r->rtm_family == AF_INET6) { if (filter.tb) { if (filter.tb < 0) { if (!(r->rtm_flags&RTM_F_CLONED)) { return 0; } } else { if (r->rtm_flags&RTM_F_CLONED) { return 0; } if (filter.tb == RT_TABLE_LOCAL) { if (r->rtm_type != RTN_LOCAL) { return 0; } } else if (filter.tb == RT_TABLE_MAIN) { if (r->rtm_type == RTN_LOCAL) { return 0; } } else { return 0; } } } } else { if (filter.tb > 0 && filter.tb != r->rtm_table) { return 0; } } if (filter.rdst.family && (r->rtm_family != filter.rdst.family || filter.rdst.bitlen > r->rtm_dst_len)) { return 0; } if (filter.mdst.family && (r->rtm_family != filter.mdst.family || (filter.mdst.bitlen >= 0 && filter.mdst.bitlen < r->rtm_dst_len))) { return 0; } if (filter.rsrc.family && (r->rtm_family != filter.rsrc.family || filter.rsrc.bitlen > r->rtm_src_len)) { return 0; } if (filter.msrc.family && (r->rtm_family != filter.msrc.family || (filter.msrc.bitlen >= 0 && filter.msrc.bitlen < r->rtm_src_len))) { return 0; } memset(tb, 0, sizeof(tb)); parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len); if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen)) return 0; if (filter.mdst.family && filter.mdst.bitlen >= 0 && inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len)) return 0; if (filter.rsrc.family && inet_addr_match(&src, &filter.rsrc, filter.rsrc.bitlen)) return 0; if (filter.msrc.family && filter.msrc.bitlen >= 0 && inet_addr_match(&src, &filter.msrc, r->rtm_src_len)) return 0; if (filter.flushb && r->rtm_family == AF_INET6 && r->rtm_dst_len == 0 && r->rtm_type == RTN_UNREACHABLE && tb[RTA_PRIORITY] && *(int*)RTA_DATA(tb[RTA_PRIORITY]) == -1) return 0; if (filter.flushb) { struct nlmsghdr *fn; if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { if (flush_update()) return -1; } fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); memcpy(fn, n, n->nlmsg_len); fn->nlmsg_type = RTM_DELROUTE; fn->nlmsg_flags = NLM_F_REQUEST; fn->nlmsg_seq = ++filter.rth->seq; filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb; filter.flushed++; return 0; } if (n->nlmsg_type == RTM_DELROUTE) { fprintf(fp, "Deleted "); } if (r->rtm_type != RTN_UNICAST && !filter.type) { fprintf(fp, "%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1))); } if (tb[RTA_DST]) { if (r->rtm_dst_len != host_len) { fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), RTA_DATA(tb[RTA_DST]), abuf, sizeof(abuf)), r->rtm_dst_len ); } else { fprintf(fp, "%s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_DST]), RTA_DATA(tb[RTA_DST]), abuf, sizeof(abuf)) ); } } else if (r->rtm_dst_len) { fprintf(fp, "0/%d ", r->rtm_dst_len); } else { fprintf(fp, "default "); } if (tb[RTA_SRC]) { if (r->rtm_src_len != host_len) { fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family, RTA_PAYLOAD(tb[RTA_SRC]), RTA_DATA(tb[RTA_SRC]), abuf, sizeof(abuf)), r->rtm_src_len ); } else { fprintf(fp, "from %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_SRC]), RTA_DATA(tb[RTA_SRC]), abuf, sizeof(abuf)) ); } } else if (r->rtm_src_len) { fprintf(fp, "from 0/%u ", r->rtm_src_len); } if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) { fprintf(fp, "via %s ", format_host(r->rtm_family, RTA_PAYLOAD(tb[RTA_GATEWAY]), RTA_DATA(tb[RTA_GATEWAY]), abuf, sizeof(abuf))); } if (tb[RTA_OIF] && filter.oifmask != -1) { fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); } if (tb[RTA_PREFSRC] && filter.rprefsrc.bitlen != host_len) { /* Do not use format_host(). It is our local addr and symbolic name will not be useful. */ fprintf(fp, " src %s ", rt_addr_n2a(r->rtm_family, RTA_PAYLOAD(tb[RTA_PREFSRC]), RTA_DATA(tb[RTA_PREFSRC]), abuf, sizeof(abuf))); } if (tb[RTA_PRIORITY]) { fprintf(fp, " metric %d ", *(__u32*)RTA_DATA(tb[RTA_PRIORITY])); } if (r->rtm_family == AF_INET6) { struct rta_cacheinfo *ci = NULL; if (tb[RTA_CACHEINFO]) { ci = RTA_DATA(tb[RTA_CACHEINFO]); } if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) { static int hz; if (!hz) { hz = get_hz(); } if (r->rtm_flags & RTM_F_CLONED) { fprintf(fp, "%s cache ", _SL_); } if (ci->rta_expires) { fprintf(fp, " expires %dsec", ci->rta_expires/hz); } if (ci->rta_error != 0) { fprintf(fp, " error %d", ci->rta_error); } } else if (ci) { if (ci->rta_error != 0) fprintf(fp, " error %d", ci->rta_error); } } if (tb[RTA_IIF] && filter.iifmask != -1) { fprintf(fp, " iif %s", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_IIF]))); } fprintf(fp, "\n"); fflush(fp); return 0; }