Home | History | Annotate | Download | only in btreplay

Lines Matching refs:tip

122  * @tip:	Pointer to per-thread information this IO is associated with
128 struct thr_info *tip;
265 * @tip: Per-thread information
267 static inline int is_send_done(struct thr_info *tip)
269 return signal_done || tip->send_done;
274 * @tip: Per-thread information
276 static inline int is_reap_done(struct thr_info *tip)
278 return tip->send_done && tip->naios_out == 0;
526 * @tip: Thread information
528 static void pin_to_cpu(struct thr_info *tip)
532 assert(0 <= tip->cpu && tip->cpu < ncpus);
535 CPU_SET(tip->cpu, &cpus);
546 fprintf(tip->vfp, "Pinned to CPU %02d ", tip->cpu);
548 fprintf(tip->vfp, "%1d", CPU_ISSET(i, &now));
549 fprintf(tip->vfp, "\n");
695 * @tip: Per-thread information
698 static void iocb_init(struct thr_info *tip, struct iocb_pkt *iocbp)
700 iocbp->tip = tip;
736 io_prep_pread(iop, iocbp->tip->ofd, buf, n, off);
739 io_prep_pwrite(iop, iocbp->tip->ofd, buf, n, off);
755 static void tip_init(struct thr_info *tip)
759 INIT_LIST_HEAD(&tip->free_iocbs);
760 INIT_LIST_HEAD(&tip->used_iocbs);
762 pthread_mutex_init(&tip->mutex, NULL);
763 pthread_cond_init(&tip->cond, NULL);
765 if (io_setup(naios, &tip->ctx)) {
770 tip->ofd = -1;
771 tip->naios_out = 0;
772 tip->send_done = tip->reap_done = 0;
773 tip->send_wait = tip->reap_wait = 0;
775 memset(&tip->sub_thread, 0, sizeof(tip->sub_thread));
776 memset(&tip->rec_thread, 0, sizeof(tip->rec_thread));
781 iocb_init(tip, iocbp);
782 list_add_tail(&iocbp->head, &tip->free_iocbs);
784 tip->naios_free = naios;
789 sprintf(fn, "%s/%s.%s.%d.rep", idir, tip->devnm, ibase,
790 tip->cpu);
791 tip->vfp = fopen(fn, "w");
792 if (!tip->vfp) {
797 setlinebuf(tip->vfp);
800 if (pthread_create(&tip->sub_thread, NULL, replay_sub, tip)) {
806 if (pthread_create(&tip->rec_thread, NULL, replay_rec, tip)) {
816 static void tip_release(struct thr_info *tip)
820 assert(tip->send_done);
821 assert(tip->reap_done);
822 assert(list_len(&tip->used_iocbs) == 0);
823 assert(tip->naios_free == naios);
825 if (pthread_join(tip->sub_thread, NULL)) {
829 if (pthread_join(tip->rec_thread, NULL)) {
834 io_destroy(tip->ctx);
836 list_splice(&tip->used_iocbs, &tip->free_iocbs);
837 list_for_each_safe(p, q, &tip->free_iocbs) {
846 pthread_cond_destroy(&tip->cond);
847 pthread_mutex_destroy(&tip->mutex);
860 struct thr_info *tip = buf_alloc(sizeof(*tip));
866 memset(tip, 0, sizeof(*tip));
867 tip->cpu = cpu % cpus_to_use;
868 tip->iterations = def_iterations;
870 tip->ifd = open(file_name, O_RDONLY);
871 if (tip->ifd < 0) {
875 if (fstat(tip->ifd, &buf) < 0) {
885 if (read(tip->ifd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
904 close(tip->ifd);
905 free(tip);
917 tip->devnm = strdup(devnm);
918 tip->file_name = strdup(file_name);
920 list_add_tail(&tip->head, &input_files);
929 * @tip: Per-input file information
931 static void rem_input_file(struct thr_info *tip)
933 list_del(&tip->head);
935 tip_release(tip);
937 close(tip->ofd);
938 close(tip->ifd);
939 free(tip->file_name);
940 free(tip->devnm);
941 free(tip);
1006 static int reap_wait_aios(struct thr_info *tip)
1010 if (!is_reap_done(tip)) {
1011 pthread_mutex_lock(&tip->mutex);
1012 while (tip->naios_out == 0) {
1013 tip->reap_wait = 1;
1014 if (pthread_cond_wait(&tip->cond, &tip->mutex)) {
1020 naios = tip->naios_out;
1021 pthread_mutex_unlock(&tip->mutex);
1023 assert(is_reap_done(tip) || naios > 0);
1025 return is_reap_done(tip) ? 0 : naios;
1030 * @tip: Per-thread information
1033 static void reclaim_ios(struct thr_info *tip, long naios_out)
1041 ndone = io_getevents(tip->ctx, 1, naios_out, events, NULL);
1053 pthread_mutex_lock(&tip->mutex);
1066 list_move_tail(&iocbp->head, &tip->free_iocbs);
1069 tip->naios_free += ndone;
1070 tip->naios_out -= ndone;
1071 naios_out = minl(naios_out, tip->naios_out);
1073 if (tip->send_wait) {
1074 tip->send_wait = 0;
1075 pthread_cond_signal(&tip->cond);
1077 pthread_mutex_unlock(&tip->mutex);
1093 struct thr_info *tip = arg;
1095 while ((naios_out = reap_wait_aios(tip)) > 0)
1096 reclaim_ios(tip, naios_out);
1098 assert(tip->send_done);
1099 tip->reap_done = 1;
1113 * @tip: Per-thread information
1118 static int next_bunch(struct thr_info *tip, struct io_bunch *bunch)
1122 result = read(tip->ifd, &bunch->hdr, sizeof(bunch->hdr));
1127 fatal(tip->file_name, ERR_SYSCALL, "Short hdr(%ld)\n",
1134 result = read(tip->ifd, &bunch->pkts, count);
1136 fatal(tip->file_name, ERR_SYSCALL, "Short pkts(%ld/%ld)\n",
1151 static int nfree_current(struct thr_info *tip)
1155 pthread_mutex_lock(&tip->mutex);
1156 while (!is_send_done(tip) && ((nfree = tip->naios_free) == 0)) {
1157 tip->send_wait = 1;
1158 if (pthread_cond_wait(&tip->cond, &tip->mutex)) {
1164 pthread_mutex_unlock(&tip->mutex);
1174 static void stall(struct thr_info *tip, long long oclock)
1182 fprintf(tip->vfp, " stall(%lld.%09lld, %lld.%09lld)\n",
1186 while (!is_send_done(tip) && tclock < oclock) {
1192 fprintf(tip->vfp, "++ stall(%lld.%09lld) ++\n",
1206 * @tip: Per-thread information
1211 static void iocbs_map(struct thr_info *tip, struct iocb **list,
1219 pthread_mutex_lock(&tip->mutex);
1220 assert(ntodo <= list_len(&tip->free_iocbs));
1229 fprintf(tip->vfp, "\t%10llu + %10llu %c%c\n",
1235 iocbp = list_entry(tip->free_iocbs.next, struct iocb_pkt, head);
1238 list_move_tail(&iocbp->head, &tip->used_iocbs);
1242 tip->naios_free -= ntodo;
1243 assert(tip->naios_free >= 0);
1244 pthread_mutex_unlock(&tip->mutex);
1249 * @tip: Per-thread information
1252 static void process_bunch(struct thr_info *tip, struct io_bunch *bunch)
1258 while (!is_send_done(tip) && (i < bunch->hdr.npkts)) {
1260 int ntodo = min(nfree_current(tip), bunch->hdr.npkts - i);
1263 iocbs_map(tip, list, &bunch->pkts[i], ntodo);
1265 stall(tip, bunch->hdr.time_stamp - genesis);
1269 fprintf(tip->vfp, "submit(%d)\n", ntodo);
1270 ndone = io_submit(tip->ctx, ntodo, list);
1274 tip->cpu, ntodo, ndone,
1279 pthread_mutex_lock(&tip->mutex);
1280 tip->naios_out += ndone;
1281 assert(tip->naios_out <= naios);
1282 if (tip->reap_wait) {
1283 tip->reap_wait = 0;
1284 pthread_cond_signal(&tip->cond);
1286 pthread_mutex_unlock(&tip->mutex);
1296 * @tip: Thread information
1300 static void reset_input_file(struct thr_info *tip)
1304 lseek(tip->ifd, 0, 0);
1306 if (read(tip->ifd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
1307 fatal(tip->file_name, ERR_ARGS, "Header reread failed\n");
1319 struct thr_info *tip = arg;
1322 pin_to_cpu(tip);
1324 sprintf(path, "/dev/%s", map_dev(tip->devnm));
1331 tip->ofd = open(path, O_RDWR | O_DIRECT | oflags);
1332 if (tip->ofd < 0) {
1338 while (!is_send_done(tip) && tip->iterations--) {
1341 fprintf(tip->vfp, "\n=== %d ===\n", tip->iterations);
1342 while (!is_send_done(tip) && next_bunch(tip, &bunch))
1343 process_bunch(tip, &bunch);
1345 reset_input_file(tip);
1347 tip->send_done = 1;