void ChatCore::tryconnect(const QString& nickname, const QString& ip, const QString& port) { auto thread = new QThread(this); if (server != nullptr) { server->destroy_connection(); delete server; } server = new Server(nickname.toStdString(), ip.toStdString(), port.toInt()); // server->moveToThread(thread); connect(thread, SIGNAL(started()), server, SLOT(establish_connection())); connect(server, SIGNAL(connected()), this, SLOT(connection_established())); connect(server, SIGNAL(readyRead()), this, SLOT(message_received())); connect(server, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connection_failed(QAbstractSocket::SocketError))); connect(server, SIGNAL(stop_thread()), thread, SLOT(quit())); thread->start(); }
void send_message(const char* hostname, const char* port, char message) { /* Connect to ssh-tunneld and deliver the message * to either open or close a connection. * Expect ssh-tunneld to be listening on port 1081. */ int sock_fd = establish_connection(hostname, port); if (sock_fd == -1) { fprintf(stderr, "Could not connect to ssh-tunneld running on %s:%s\n", hostname, port); exit(EXIT_FAILURE); } /* now send a message to the ssh-tunneld */ if (send(sock_fd, &message, sizeof(message), 0) != 1) { perror("send"); exit(EXIT_FAILURE); } /* read the response that tells us when the tunnel is active (or that our disconnect request * was acknowledge) */ char buffer[1]; if (recv(sock_fd, &buffer, sizeof(buffer), 0) != 1) { perror("recv"); exit(EXIT_FAILURE); } if (buffer[0] != message) { fprintf(stderr, "Received incorrect response from ssh-tunneld. Exiting.\n"); exit(EXIT_FAILURE); } /* finally close the socket */ close(sock_fd); }
/* * Ensure that the environment is sane. * This involves checking the Postgresql version, and if in network mode * also establishing a connection to a receiver. */ int ensure_valid_environment(void) { StringInfoData buf; int retval; char* pgversion; SPITupleTable *coltuptable; SetCurrentStatementStartTimestamp(); StartTransactionCommand(); SPI_connect(); PushActiveSnapshot(GetTransactionSnapshot()); /* Ensure compatible version */ pgstat_report_activity(STATE_RUNNING, "verifying compatible postgres version"); initStringInfo(&buf); appendStringInfo(&buf, "select version();" ); retval = SPI_execute(buf.data, false, 0); if (retval != SPI_OK_SELECT) { elog(FATAL, "Unable to query postgres version %d", retval); SPI_finish(); PopActiveSnapshot(); CommitTransactionCommand(); return 1; } coltuptable = SPI_tuptable; pgversion = SPI_getvalue(coltuptable->vals[0], coltuptable->tupdesc, 1); if(strstr(pgversion, "PostgreSQL 9.3") == NULL) { elog(FATAL, "Unsupported Postgresql version"); SPI_finish(); PopActiveSnapshot(); CommitTransactionCommand(); return 1; } SPI_finish(); PopActiveSnapshot(); CommitTransactionCommand(); /* * Attempt to establish a connection if the output mode is network. */ if (strcmp(output_mode, "network") == 0) { retval = establish_connection(); if (retval == 2) { elog(LOG, "Error : Failed to connect to antenna please check domain is available from host."); } } //TODO verify logging directory is accessible when csv mode. elog(LOG, "Pgsampler Initialized"); return 0; }
int main (int argc, char **argv) { int n, port; char buffer[BUFLEN]={ 0 }, *router=0; pthread_attr_t reader_thread_attr; pthread_t reader_thread; if (argc != 5) { fprintf(stderr, "Usage: %s <selfid> <router hostname> <router port> <dest-id>\n",argv[0]); exit(1); } selfid = atoi (argv[1]); router=argv[2]; port=atoi(argv[3]); destination = atoi (argv[4]); establish_connection (router, port); handshake (); pthread_attr_init(&reader_thread_attr); pthread_attr_setdetachstate(&reader_thread_attr,PTHREAD_CREATE_DETACHED); pthread_create(&reader_thread,&reader_thread_attr,reader,0); n = 0; while(1) { fgets (buffer, BUFLEN,stdin); //sscanf ("%s",buffer); if(strstr(buffer,"quit")) { fprintf(stderr,"Quitting..\n"); break; } if(strstr(buffer,"send")) { //while (1) if (0 != send_packet (n++)) break; } } pthread_cancel(reader_thread); pthread_attr_destroy(&reader_thread_attr); printf("Connection closed.\n"); close(sd); return 0; }
int main(int argc, char *argv[]) { int temp; int loops = 0; int did_work; socklen_t addrlen = sizeof(struct sockaddr_storage); uber_state_t *uber_state; event_state_select_t *mumble; connection_t *connection_list; connection_t *temp_connection; uber_state = (uber_state_t *)malloc(sizeof(uber_state_t)); uber_state->connection_list = NULL; uber_state->event_state = init_event_state(); mumble = uber_state->event_state; uber_state->rdwr_since_accept = 0; fprintf(stderr,"Hello there, let's generate some transactions. Uberstate %p connection_list %p event_state %p\n", uber_state,uber_state->connection_list,uber_state->event_state); for (loops = 0; loops < atoi(argv[3]); loops++) { temp = establish_connection(argv[1],argv[2],AF_INET,&addrlen); /* initialize our event_state minfd */ /* mumble->minfd = temp; */ temp_connection = add_new_connection(uber_state, temp, CONNECTION_WRITING, 128); fprintf(stderr,"temp_connection is at %p\n",temp_connection); } do { loops++; if (debug > 1) { fprintf(stderr,"\nabout to walk loop %d\n",loops); } did_work = walk_connection_list(uber_state); if (!did_work) { if (debug) { fprintf(stderr, "walk_connection_list did no work, time to wait\n"); } did_work = wait_for_events_and_walk(uber_state); } } while (1); }
static void JNICALL dumperThreadMain(__UNUSED__ jvmtiEnv* jvmti, JNIEnv* jni_env, __UNUSED__ void* arg) { char* internalLeaksString; if (JNI_FALSE != __sync_lock_test_and_set(&gdata->dumpInProgress, JNI_TRUE)) { alert("Another dump is already in progress"); return; } gdata->numberOfLeaks = 0; initThreadData(jni_env); if (gdata->run_gc) { jvmtiError err; debug("jleaker: Running garbage collection\n"); err = (*jvmti)->ForceGarbageCollection(jvmti); if (err) alert("jleaker: Failed to run GC\n"); } establish_connection(gdata->tcp_port); begin_xml_output(); open_xml_element("memory-leaks", NULL); startTimer(&getThreadData()->timer, 0); tagAllMapsAndCollections(); findLeaksInTaggedObjects(); close_xml_element("memory-leaks"); close_connection(); stopTimer(&getThreadData()->timer, "Finished leak detection"); releaseThreadData(); internalLeaksString = findInternalMallocsLeaks(); if (NULL != internalLeaksString) { alert("Internal jleaker error: %s\n", internalLeaksString); free(internalLeaksString); } if (gdata->self_check) { selfCheck(); } gdata->dumpInProgress = JNI_FALSE; }
/** Cria, envia e armazena a comunicacao entre o cliente e o host. * * Essa e a funcao principal desse modulo. @n * Nela estao as chamadas para todas as funcoes secundarias, cada uma * lidando com seus proprios erros, dentro de seus escopos. @n * Pode-se dizer que aqui esta a logica de todo esse mo'dulo. * * @see tex_parse_uri() * @see create_talking_socket() * @see establish_socket_address() * @see establish_connection() * @see send_data() * @see receive_data() */ void net_communicate () { int local_socket; struct sockaddr_in socket_address; tex_parse_uri (); local_socket = create_talking_socket(); establish_socket_address(&socket_address); establish_connection(&local_socket, &socket_address); send_data(&local_socket); receive_data(&local_socket); }
/* * Main * --------------------------------------------------------------------- * - just a wrapper over the inpotrant functions, as ussual */ int main (int argc, char * argv[]) { struct keep_data data; if (parse_arguments(argc, argv, &data) != EXIT_SUCCESS) return EXIT_FAILURE; int sock; if (establish_connection(&data, &sock) != EXIT_SUCCESS) return EXIT_FAILURE; if (send_data(&data.msg, &sock) != EXIT_SUCCESS) return EXIT_FAILURE; char * buffer = NULL; if (get_respose(&sock, &buffer) != EXIT_SUCCESS) return EXIT_FAILURE; print_result(buffer); close(sock); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int ret; int session_id; plan_tests(NUM_TESTS); diag("Live unit tests"); ret = connect_viewer("localhost"); ok(ret == 0, "Connect viewer to relayd"); ret = establish_connection(); ok(ret == 0, "Established connection and version check with %d.%d", VERSION_MAJOR, VERSION_MINOR); ret = list_sessions(&session_id); ok(ret > 0, "List sessions : %d session(s)", ret); ret = attach_session(session_id); ok(ret > 0, "Attach to session, %d streams received", ret); ret = get_metadata(); ok(ret > 0, "Get metadata, received %d bytes", ret); ret = get_next_index(); ok(ret == 0, "Get one index per stream"); ret = get_data_packet(first_packet_stream_id, first_packet_offset, first_packet_len); ok(ret == first_packet_len, "Get one data packet for stream %d, offset %d, len %d", first_packet_stream_id, first_packet_offset, first_packet_len); return exit_status(); }
int main(int argc, char *argv[]) { int ret_parser,i = 0; struct ibv_device *ib_dev = NULL; struct pingpong_context ctx; struct pingpong_dest *my_dest = NULL; struct pingpong_dest *rem_dest = NULL; struct perftest_parameters user_param; struct perftest_comm user_comm; struct bw_report_data my_bw_rep, rem_bw_rep; /* init default values to user's parameters */ memset(&ctx,0,sizeof(struct pingpong_context)); memset(&user_param , 0 , sizeof(struct perftest_parameters)); memset(&user_comm,0,sizeof(struct perftest_comm)); user_param.verb = READ; user_param.tst = BW; strncpy(user_param.version, VERSION, sizeof(user_param.version)); ret_parser = parser(&user_param,argv,argc); if (ret_parser) { if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT) fprintf(stderr," Parser function exited with Error\n"); return 1; } if((user_param.connection_type == DC || user_param.use_xrc) && user_param.duplex) { user_param.num_of_qps *= 2; } ib_dev =ctx_find_dev(user_param.ib_devname); if (!ib_dev) return 7; /* Getting the relevant context from the device */ ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } /* See if MTU and link type are valid and supported. */ if (check_link(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } /* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */ if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) { printf("\n************************************\n"); printf("* Waiting for client to connect... *\n"); printf("************************************\n"); } /* Initialize the connection and print the local data. */ if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return FAILURE; } exchange_versions(&user_comm, &user_param); check_sys_data(&user_comm, &user_param); /* See if MTU and link type are valid and supported. */ if (check_mtu(ctx.context,&user_param, &user_comm)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } /* Print basic test information. */ ctx_print_test_info(&user_param); ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps); memset(my_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); ALLOCATE(rem_dest , struct pingpong_dest , user_param.num_of_qps); memset(rem_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); /* Allocating arrays needed for the test. */ alloc_ctx(&ctx,&user_param); /* Create (if nessacery) the rdma_cm ids and channel. */ if (user_param.work_rdma_cm == ON) { if (user_param.machine == CLIENT) { if (retry_rdma_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { /* create all the basic IB resources. */ if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } /* Set up the Connection. */ if (set_up_connection(&ctx,&user_param,my_dest)) { fprintf(stderr," Unable to set up socket connection\n"); return FAILURE; } /* Print this machine QP information */ for (i=0; i < user_param.num_of_qps; i++) ctx_print_pingpong_data(&my_dest[i],&user_comm); user_comm.rdma_params->side = REMOTE; for (i=0; i < user_param.num_of_qps; i++) { /* shaking hands and gather the other side info. */ if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } ctx_print_pingpong_data(&rem_dest[i],&user_comm); } if (user_param.work_rdma_cm == OFF) { if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) { fprintf(stderr,"\n Found Incompatibility issue with GID types.\n"); fprintf(stderr," Please Try to use a different IP version.\n\n"); return 1; } } if (user_param.work_rdma_cm == OFF) { if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return 1; } } /* An additional handshake is required after moving qp to RTR. */ if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (user_param.output == FULL_VERBOSITY) { if (user_param.report_per_port) { printf(RESULT_LINE_PER_PORT); printf((user_param.report_fmt == MBS ? RESULT_FMT_PER_PORT : RESULT_FMT_G_PER_PORT)); } else { printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); } printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); } /* For half duplex tests, server just waits for client to exit */ if (user_param.machine == SERVER && !user_param.duplex) { if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr," Failed to exchange data between server and clients\n"); return FAILURE; } xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); print_full_bw_report(&user_param, &rem_bw_rep, NULL); if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } if (user_param.output == FULL_VERBOSITY) { if (user_param.report_per_port) printf(RESULT_LINE_PER_PORT); else printf(RESULT_LINE); } if (user_param.work_rdma_cm == ON) { if (destroy_ctx(&ctx,&user_param)) { fprintf(stderr, "Failed to destroy resources\n"); return 1; } user_comm.rdma_params->work_rdma_cm = ON; return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params); } return destroy_ctx(&ctx,&user_param); } if (user_param.use_event) { if (ibv_req_notify_cq(ctx.send_cq, 0)) { fprintf(stderr, "Couldn't request CQ notification\n"); return 1; } } if (user_param.test_method == RUN_ALL) { for (i = 1; i < 24 ; ++i) { user_param.size = (uint64_t)1 << i; ctx_set_send_wqes(&ctx,&user_param,rem_dest); if(perform_warm_up(&ctx,&user_param)) { fprintf(stderr,"Problems with warm up\n"); return 1; } if(user_param.duplex) { if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to sync between server and client between different msg sizes\n"); return 1; } } if(run_iter_bw(&ctx,&user_param)) return 17; if (user_param.duplex && (atof(user_param.version) >= 4.6)) { if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to sync between server and client between different msg sizes\n"); return 1; } } print_report_bw(&user_param,&my_bw_rep); if (user_param.duplex) { xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); print_full_bw_report(&user_param, &my_bw_rep, &rem_bw_rep); } } } else if (user_param.test_method == RUN_REGULAR) { ctx_set_send_wqes(&ctx,&user_param,rem_dest); if(perform_warm_up(&ctx,&user_param)) { fprintf(stderr,"Problems with warm up\n"); return 1; } if(user_param.duplex) { if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to sync between server and client between different msg sizes\n"); return 1; } } if(run_iter_bw(&ctx,&user_param)) { fprintf(stderr," Failed to complete run_iter_bw function successfully\n"); return 1; } print_report_bw(&user_param,&my_bw_rep); if (user_param.duplex) { xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); print_full_bw_report(&user_param, &my_bw_rep, &rem_bw_rep); } if (user_param.report_both && user_param.duplex) { printf(RESULT_LINE); printf("\n Local results: \n"); printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); print_full_bw_report(&user_param, &my_bw_rep, NULL); printf(RESULT_LINE); printf("\n Remote results: \n"); printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); print_full_bw_report(&user_param, &rem_bw_rep, NULL); } } else if (user_param.test_method == RUN_INFINITELY) { ctx_set_send_wqes(&ctx,&user_param,rem_dest); if(run_iter_bw_infinitely(&ctx,&user_param)) { fprintf(stderr," Error occured while running! aborting ...\n"); return 1; } } if (user_param.output == FULL_VERBOSITY) { if (user_param.report_per_port) printf(RESULT_LINE_PER_PORT); else printf(RESULT_LINE); } /* For half duplex tests, server just waits for client to exit */ if (user_param.machine == CLIENT && !user_param.duplex) { if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr," Failed to exchange data between server and clients\n"); return FAILURE; } xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); } if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) { fprintf(stderr,"Error: BW result is below bw limit\n"); return 1; } if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON )) { fprintf(stderr,"Error: Msg rate is below msg_rate limit\n"); return 1; } if (user_param.work_rdma_cm == ON) { if (destroy_ctx(&ctx,&user_param)) { fprintf(stderr, "Failed to destroy resources\n"); return 1; } user_comm.rdma_params->work_rdma_cm = ON; return destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params); } return destroy_ctx(&ctx,&user_param); }
/*---------------------------------------------------------------------------*/ int run_server_test(struct perf_parameters *user_param) { struct server_data server_data; struct perf_command command; int i, len, retval; int max_cpus; uint64_t cpusmask; int cpusnr; int cpu; xio_init(); max_cpus = sysconf(_SC_NPROCESSORS_ONLN); i = intf_name_best_cpus(user_param->intf_name, &cpusmask, &cpusnr); if (i == 0) { printf("best cpus [%d] %s\n", cpusnr, intf_cpusmask_str(cpusmask, cpusnr, user_param->intf_name)); } server_data.my_test_param.machine_type = user_param->machine_type; server_data.my_test_param.test_type = user_param->test_type; server_data.my_test_param.verb = user_param->verb; server_data.my_test_param.data_len = 0; server_data.tdata = calloc(user_param->threads_num, sizeof(*server_data.tdata)); /* spawn portals */ for (i = 0, cpu = 0; i < user_param->threads_num; i++, cpu++) { while (1) { if (cpusmask_test_bit(cpu, &cpusmask)) break; if (++cpu == max_cpus) cpu = 0; } server_data.tdata[i].affinity = cpu; server_data.tdata[i].portal_index = (i % user_param->portals_arr_len); server_data.tdata[i].user_param = user_param; pthread_create(&server_data.tdata[i].thread_id, NULL, portal_server_cb, &server_data.tdata[i]); } server_data.user_param = user_param; pthread_create(&server_data.thread_id, NULL, balancer_server_cb, &server_data); server_data.comm = create_comm_struct(user_param); if (establish_connection(server_data.comm)) { fprintf(stderr, "failed to establish connection\n"); goto cleanup; } printf("%s", RESULT_FMT); printf("%s", RESULT_LINE); while (1) { /* sync test parameters */ retval = ctx_read_data(server_data.comm, &command, sizeof(command), &len); if (retval) { /* disconnection */ fprintf(stderr, "program aborted\n"); break; } if (len == 0) { /* handshake */ ctx_write_data(server_data.comm, NULL, 0); break; } switch (command.command) { case GetTestResults: on_test_results(&command.results); ctx_write_data(server_data.comm, NULL, 0); break; case GetTestParams: break; default: fprintf(stderr, "unknown command %d\n", len); exit(0); break; }; } if (retval == 0) printf("%s", RESULT_LINE); /* normal exit phase */ ctx_close_connection(server_data.comm); cleanup: for (i = 0; i < user_param->threads_num; i++) xio_context_stop_loop(server_data.tdata[i].ctx, 0); destroy_comm_struct(server_data.comm); /* join the threads */ for (i = 0; i < user_param->threads_num; i++) pthread_join(server_data.tdata[i].thread_id, NULL); if (server_data.running) xio_context_stop_loop(server_data.ctx, 0); pthread_join(server_data.thread_id, NULL); free(server_data.tdata); xio_shutdown(); return 0; }
int main(int argc, char **argv) { _comm_header *comm; _tag_detail *tag; _path *path; _rack *rack; _services *services; //_backplane_data *backplane; int result,x,debug=0; result = 0; while ((x = getopt(argc, argv, "dh?")) != -1) { switch (x) { case 'd': debug++; break; case 'h': case '?': helpme(); exit(1); } } // Note that this is quick and dirty - no error checking... tag = malloc(sizeof(_tag_detail)); memset(tag,0,sizeof(_tag_detail)); rack = malloc(sizeof(_rack)); memset (rack,0,sizeof(_rack)); //backplane = malloc(sizeof(_backplane_data)); //memset (backplane,0,sizeof(_backplane_data)); path = malloc(sizeof(_path)); memset (path,0,sizeof(_path)); services = malloc(sizeof(_services)); memset (services,0,sizeof(_services)); comm = malloc(sizeof(_comm_header)); memset (comm,0,sizeof(_comm_header)); dprint (DEBUG_TRACE,"setting plc name %d %s.\n",strlen(argv[1]), argv[1]); comm->hostname = argv[1]; dprint (DEBUG_TRACE,"attaching to plc\n"); establish_connection (comm, services, 0); if (comm->error != 0) { printf ("Could not attach to %s\n",argv[1]); exit(-1); } path->device1 = -1; path->device2 = -1; path->device3 = -1; path->device4 = -1; path->device5 = -1; path->device6 = -1; path->device7 = -1; path->device8 = -1; //get_backplane_data(comm, backplane, rack, path, 0); dprint (DEBUG_TRACE,"polling PLC rack layout\n"); who(comm, rack, NULL, 0); path->device1 =1; path->device2 = rack->cpulocation; dprint (DEBUG_TRACE,"reading tag\n"); if (argc == 3) result = read_tag(comm, path, NULL, argv[2], tag, 0); if (argc == 4) result = read_tag(comm, path, argv[3], argv[2], tag, 0); if (result != 0) { printf ("reading tag %s failed - does it exist?\n\n",argv[2]); exit(-1); } for (x=0; x<tag->datalen; x++) printf ("%02X ",tag->data[x]); printf ("\n\n"); exit(0); }
int main(int argc, char *argv[]) { int i = 0; int size_max_pow = 24; int ret_val; struct report_options report; struct pingpong_context ctx; struct pingpong_dest *my_dest = NULL; struct pingpong_dest *rem_dest = NULL; struct mcast_parameters mcg_params; struct ibv_device *ib_dev = NULL; struct perftest_parameters user_param; struct perftest_comm user_comm; /* init default values to user's parameters */ memset(&ctx, 0, sizeof(struct pingpong_context)); memset(&user_param, 0, sizeof(struct perftest_parameters)); memset(&user_comm , 0, sizeof(struct perftest_comm)); memset(&mcg_params, 0, sizeof(struct mcast_parameters)); user_param.verb = SEND; user_param.tst = LAT; strncpy(user_param.version, VERSION, sizeof(user_param.version)); user_param.r_flag = &report; // Configure the parameters values according to user arguments or defalut values. ret_val = parser(&user_param,argv,argc); if (ret_val) { if (ret_val != VERSION_EXIT && ret_val != HELP_EXIT) fprintf(stderr," Parser function exited with Error\n"); return 1; } if(user_param.use_xrc || user_param.connection_type == DC) { user_param.num_of_qps *= 2; } //Checking that the user did not run with RawEth. for this we have raw_etherent_bw test. if (user_param.connection_type == RawEth) { fprintf(stderr," This test cannot run Raw Ethernet QPs (you have chosen RawEth as connection type\n"); return FAILURE; } // Finding the IB device selected (or defalut if no selected). ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE device\n"); return 1; } if (user_param.use_mcg) GET_STRING(mcg_params.ib_devname,ibv_get_device_name(ib_dev)); // Getting the relevant context from the device ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } // See if MTU and link type are valid and supported. if (check_link(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // copy the relevant user parameters to the comm struct + creating rdma_cm resources. if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) { printf("\n************************************\n"); printf("* Waiting for client to connect... *\n"); printf("************************************\n"); } // Initialize the connection and print the local data. if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return FAILURE; } exchange_versions(&user_comm, &user_param); check_sys_data(&user_comm, &user_param); // See if MTU and link type are valid and supported. if (check_mtu(ctx.context,&user_param, &user_comm)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // Print basic test information. ctx_print_test_info(&user_param); ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps); memset(my_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); ALLOCATE(rem_dest , struct pingpong_dest , user_param.num_of_qps); memset(rem_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); // Allocating arrays needed for the test. alloc_ctx(&ctx,&user_param); // Create (if nessacery) the rdma_cm ids and channel. if (user_param.work_rdma_cm == ON) { if (user_param.machine == CLIENT) { if (retry_rdma_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { // create all the basic IB resources (data buffer, PD, MR, CQ and events channel) if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } // Set up the Connection. if (send_set_up_connection(&ctx,&user_param,my_dest,&mcg_params,&user_comm)) { fprintf(stderr," Unable to set up socket connection\n"); return 1; } for (i=0; i < user_param.num_of_qps; i++) ctx_print_pingpong_data(&my_dest[i],&user_comm); user_comm.rdma_params->side = REMOTE; for (i=0; i < user_param.num_of_qps; i++) { // shaking hands and gather the other side info. if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } ctx_print_pingpong_data(&rem_dest[i],&user_comm); } if (user_param.work_rdma_cm == OFF) { if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) { fprintf(stderr,"\n Found Incompatibility issue with GID types.\n"); fprintf(stderr," Please Try to use a different IP version.\n\n"); return 1; } } if (user_param.use_mcg) { memcpy(mcg_params.base_mgid.raw,mcg_params.mgid.raw,16); memcpy(mcg_params.mgid.raw,rem_dest[0].gid.raw,16); mcg_params.base_mlid = mcg_params.mlid; mcg_params.is_2nd_mgid_used = ON; if (!strcmp(link_layer_str(user_param.link_type),"IB")) { // Request for Mcast group create registery in SM. if (join_multicast_group(SUBN_ADM_METHOD_SET,&mcg_params)) { fprintf(stderr," Failed to Join Mcast request\n"); return 1; } } /* * The next stall in code (50 ms sleep) is a work around for fixing the * the bug this test had in Multicast for the past 1 year. * It appears, that when a switch involved, it takes ~ 10 ms for the join * request to propogate on the IB fabric, thus we need to wait for it. * what happened before this fix was reaching the post_send * code segment in about 350 ns from here, and the switch(es) dropped * the packet because join request wasn't finished. */ usleep(50000); } if (user_param.work_rdma_cm == OFF) { // Prepare IB resources for rtr/rts. if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return 1; } } // shaking hands and gather the other side info. if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (user_param.use_event) { if (ibv_req_notify_cq(ctx.send_cq, 0)) { fprintf(stderr, "Couldn't request RCQ notification\n"); return 1; } if (ibv_req_notify_cq(ctx.recv_cq, 0)) { fprintf(stderr, "Couldn't request RCQ notification\n"); return 1; } } if (user_param.output == FULL_VERBOSITY) { printf(RESULT_LINE); printf("%s",(user_param.test_type == ITERATIONS) ? RESULT_FMT_LAT : RESULT_FMT_LAT_DUR); printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); } ctx_set_send_wqes(&ctx,&user_param,rem_dest); if (user_param.test_method == RUN_ALL) { if (user_param.connection_type == UD) size_max_pow = (int)UD_MSG_2_EXP(MTU_SIZE(user_param.curr_mtu)) + 1; for (i = 1; i < size_max_pow ; ++i) { user_param.size = (uint64_t)1 << i; // Post recevie recv_wqes fo current message size if (ctx_set_recv_wqes(&ctx,&user_param)) { fprintf(stderr," Failed to post receive recv_wqes\n"); return 1; } // Sync between the client and server so the client won't send packets // Before the server has posted his receive wqes (in UC/UD it will result in a deadlock). if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if(run_iter_lat_send(&ctx, &user_param)) return 17; user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param); } } else { // Post recevie recv_wqes fo current message size if (ctx_set_recv_wqes(&ctx,&user_param)) { fprintf(stderr," Failed to post receive recv_wqes\n"); return 1; } // Sync between the client and server so the client won't send packets // Before the server has posted his receive wqes (in UC/UD it will result in a deadlock). if (ctx_hand_shake(&user_comm,my_dest,rem_dest)) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if(run_iter_lat_send(&ctx, &user_param)) return 17; user_param.test_type == ITERATIONS ? print_report_lat(&user_param) : print_report_lat_duration(&user_param); } if (user_param.output == FULL_VERBOSITY) { printf(RESULT_LINE); } if (ctx_close_connection(&user_comm,my_dest,rem_dest)) { fprintf(stderr,"Failed to close connection between server and client\n"); fprintf(stderr," Trying to close this side resources\n"); } return send_destroy_ctx(&ctx,&user_param,&mcg_params); }
int main(int argc, char *argv[]) { /* //www.fileserve.com/file/u8xEmG8/how.i.met.your.mother.s06e12.hdtv.xvid-fqm.avi char *path = "/file/u8xEmG8/how.i.met.your.mother.s06e12.hdtv.xvid-fqm.avi"; char *domain = "www.fileserve.com"; char *port = "80"; char *remote, *request; char buffer[BUF_SIZE]; struct addrinfo hints, *ai, *ai0; int fd, i; // Resolve the domain name memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; // Create the request with respect to the presence of a proxy //request = malloc(strlen("GET HTTP/1.1\r\nHost: \r\n\r\n") + strlen(path) + strlen(domain) + 1); request = "POST /login.php HTTP/1.1\r\n" "Host: www.fileserve.com\r\n" "Content-Length: 164\r\n" "Content-Type: application/x-www-form-urlencoded\r\n\r\n" "loginUserName=adraen&loginUserPassword=N3YL9RL5&autoLogin=on&recaptcha_response_field=&recaptcha_challenge_field=&recaptcha_shortencode_field=&loginFormSubmit=Login"; remote = domain; port = port; //sprintf(request, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", path, domain); // try to resolve the dns if ((i = getaddrinfo(remote, port, &hints, &ai0)) != 0) { //free(request); return EXIT_FAILURE; } // Loop through the linked list of addressinfo returned by getaddrinfo for (ai = ai0; ai != NULL; ai = ai->ai_next) { // create the socket fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); // check if it has been properly created or try next addrinfo if (fd == -1) continue; // try to connect or try next addrinfo if (connect(fd, ai->ai_addr, ai->ai_addrlen) == -1) { close(fd); continue; } // Send the request if(write(fd, request, strlen(request)) == -1) { return 0; } //free(request); // Read the header from the socket ssize_t rcount = 0; char *eoh; // End of Header do { rcount = read(fd, buffer + rcount, BUF_SIZE - rcount); if (rcount == -1) { return EXIT_FAILURE; } } while (((eoh = strstr(buffer, "\r\n\r\n")) == NULL) && (rcount != 0)); printf(buffer); //retrieve the cookie from the header char *socookie = strstr(buffer, "Set-Cookie: ") + 12; socookie = strstr(socookie, "Set-Cookie: ") + 12; char *eocookie = strstr(socookie, "\r\n"); int len = eocookie - socookie; char *cookie = malloc(len + 1); strncpy(cookie, socookie, len); cookie[len] = 0; printf("\n%s\n", cookie); // purge the read do { rcount = read(fd, buffer, BUF_SIZE); } while (rcount > 0); // write the get request request = malloc(strlen("GET HTTP/1.1\r\nHost: \r\nCookie: \r\n\r\n") + strlen(path) + strlen(domain) + strlen(cookie) + 1); sprintf(request, "GET %s HTTP/1.1\r\nHost: %s\r\nCookie: %s\r\n\r\n", path, domain, cookie); write(fd, request, strlen(request)); read(fd, buffer, BUF_SIZE); printf(buffer); close(fd); return EXIT_SUCCESS; } // At this point the connection has been unsuccesfull return EXIT_FAILURE; */ char *addr = "http://www.fileserve.com/login.php"; URL_t url; int fd; // Parse the input url if (url_parse(addr, &url) != 0) { fprintf(stderr, "Unable to connect to <url>"); return EXIT_FAILURE; } if ((fd = establish_connection(url)) == -1) { fprintf(stderr, "Unable to connect to <url>"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int i = 0; struct report_options report = {}; struct pingpong_context ctx; struct ibv_device *ib_dev; struct perftest_parameters user_param; struct pingpong_dest my_dest,rem_dest; struct perftest_comm user_comm; /* init default values to user's parameters */ memset(&ctx,0,sizeof(struct pingpong_context)); memset(&user_param,0,sizeof(struct perftest_parameters)); memset(&user_comm,0,sizeof(struct perftest_comm)); memset(&my_dest,0,sizeof(struct pingpong_dest)); memset(&rem_dest,0,sizeof(struct pingpong_dest)); user_param.verb = READ; user_param.tst = LAT; user_param.r_flag = &report; user_param.version = VERSION; // Configure the parameters values according to user arguments or defalut values. if (parser(&user_param,argv,argc)) { fprintf(stderr," Parser function exited with Error\n"); return FAILURE; } // Finding the IB device selected (or defalut if no selected). ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE deivce\n"); return FAILURE; } // Getting the relevant context from the device ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } // See if MTU and link type are valid and supported. if (check_link_and_mtu(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // Print basic test information. ctx_print_test_info(&user_param); // copy the rellevant user parameters to the comm struct + creating rdma_cm resources. if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } // Create (if nessacery) the rdma_cm ids and channel. if (user_param.work_rdma_cm == ON) { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (user_param.machine == CLIENT) { if (rdma_client_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { // create all the basic IB resources (data buffer, PD, MR, CQ and events channel) if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } // Set up the Connection. if (set_up_connection(&ctx,&user_param,&my_dest)) { fprintf(stderr," Unable to set up socket connection\n"); return 1; } ctx_print_pingpong_data(&my_dest,&user_comm); // Init the connection and print the local data. if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return 1; } // shaking hands and gather the other side info. if (ctx_hand_shake(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to exchange date between server and clients\n"); return 1; } user_comm.rdma_params->side = REMOTE; ctx_print_pingpong_data(&rem_dest,&user_comm); if (user_param.work_rdma_cm == OFF) { if (pp_connect_ctx(&ctx,my_dest.psn,&rem_dest,my_dest.out_reads,&user_param)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return 1; } } // An additional handshake is required after moving qp to RTR. if (ctx_hand_shake(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to exchange date between server and clients\n"); return 1; } ALLOCATE(tstamp,cycles_t,user_param.iters); // Only Client post read request. if (user_param.machine == SERVER) { if (ctx_close_connection(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; // destroy_ctx(&ctx,&user_param); } if (user_param.use_event) { if (ibv_req_notify_cq(ctx.send_cq, 0)) { fprintf(stderr, "Couldn't request CQ notification\n"); return 1; } } printf(RESULT_LINE); printf(RESULT_FMT_LAT); if (user_param.all == ON) { for (i = 1; i < 24 ; ++i) { user_param.size = 1 << i; if(run_iter(&ctx,&user_param,&rem_dest)) return 17; print_report(&user_param); } } else { if(run_iter(&ctx,&user_param,&rem_dest)) return 18; print_report(&user_param); } if (ctx_close_connection(&user_comm,&my_dest,&rem_dest)) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; // destroy_ctx(&ctx,&user_param); }
int main(int argc, char **argv) { _comm_header *comm; _path *path; _services *services; _backplane_data *backplane; _rack *rack; _tag_data *configtags, *detailtags; _tag_data *program_tags[64]; _tag_list *list; _prog_list *progs; _struct_list *structs; int x, y, z, debug, program_count, quiet, result; int c1 = 0, c68 = 0, c69 = 0; #ifdef WIN32 int optind = 1; debug = DEBUG_DATA; #endif #ifndef WIN32 debug = 0; #endif program_count = 0; quiet = FALSE; if (argc == 1) { helpme(); exit(1); } #ifndef WIN32 while ((x = getopt(argc, argv, "dhq?")) != -1) { switch (x) { case 'd': debug++; break; case 'q': quiet = TRUE; break; case 'h': case '?': helpme(); exit(1); } } #endif if (argv[optind] == NULL) { printf("Can not connect - need a host name to connect to.\n"); exit(-1); } rack = malloc(sizeof(_rack)); if (rack == NULL) { printf("Could not allocate memory for rack structure.\n"); exit(-1); } comm = malloc(sizeof(_comm_header)); if (comm == NULL) { printf("Could not allocate memory for comm header.\n"); exit(-1); } services = malloc(sizeof(_services)); if (services == NULL) { printf("Could not allocate memory for services structure.\n"); free(comm); exit(-1); } backplane = malloc(sizeof(_backplane_data)); if (backplane == NULL) { printf("Could not allocate memory for backplane structure.\n"); free(comm); free(services); exit(-1); } path = malloc(sizeof(_path)); if (path == NULL) { printf("Could not allocate memory for path structure.\n"); free(backplane); free(comm); free(services); exit(-1); } configtags = malloc(sizeof(_tag_data)); if (configtags == NULL) { printf("Could not allocate memory for configtags structure.\n"); free(path); free(backplane); free(comm); free(services); exit(-1); } detailtags = malloc(sizeof(_tag_data)); if (detailtags == NULL) { printf("Could not allocate memory for detailtags structure.\n"); free(path); free(backplane); free(comm); free(services); exit(-1); } progs = malloc(sizeof(_prog_list)); if (progs == NULL) { printf("Could not allocate memory for program list structure.\n"); free(detailtags); free(path); free(backplane); free(comm); free(services); exit(-1); } structs = malloc(sizeof(_struct_list)); if (structs == NULL) { printf("Could not allocate memory for structure list.\n"); exit(-1); } list = malloc(sizeof(_tag_list)); if (list == NULL) { printf ("Could not allocate memory for tag list.\n"); exit(-1); } memset(services, 0, sizeof(_services)); memset(comm, 0, sizeof(_comm_header)); memset(backplane, 0, sizeof(_backplane_data)); memset(rack, 0, sizeof(_rack)); memset(configtags, 0, sizeof(_tag_data)); memset(detailtags, 0, sizeof(_tag_data)); memset(progs, 0, sizeof(_prog_list)); memset(structs, 0, sizeof(_struct_list)); memset(list, 0, sizeof(_tag_list)); comm->hostname = argv[optind]; if (quiet == FALSE) printf("Connecting to host %s\n", comm->hostname); establish_connection(comm, services, debug); if (comm->error != OK) { printf("An Error occured while connecting to host %s.\n", comm->hostname); exit(-1); } path->device1 = -1; path->device2 = -1; path->device3 = -1; path->device4 = -1; path->device5 = -1; path->device6 = -1; path->device7 = -1; path->device8 = -1; if (quiet == FALSE) printf("Got Session_ID = %ld\n", comm->session_id); get_backplane_data(comm, backplane, rack, path, debug); if (debug != DEBUG_NIL) { dprint(DEBUG_VALUES, "RX_Bad_m :%02X ", backplane->rx_bad_m); dprint(DEBUG_VALUES, "ERR+Threshold: %02X ", backplane->err_threshold); dprint(DEBUG_VALUES, "RX_Bad_CRC :%02X ", backplane->rx_bad_crc); dprint(DEBUG_VALUES, "RX_Bus_Timeout :%02X\n", backplane->rx_bus_timeout); dprint(DEBUG_VALUES, "TX_Bad_CRC :%02X ", backplane->tx_bad_crc); dprint(DEBUG_VALUES, "TX_Bus_Timeout :%02X ", backplane->tx_bus_timeout); dprint(DEBUG_VALUES, "TX_Retry :%02X\n", backplane->tx_retry); dprint(DEBUG_VALUES, "Status :%02X ", backplane->status); dprint(DEBUG_VALUES, "Address :%04X\n", backplane->address); dprint(DEBUG_VALUES, "Major Rev :%02X ", backplane->rev_major); dprint(DEBUG_VALUES, "Minor Rev :%02X ", backplane->rev_minor); dprint(DEBUG_VALUES, "Serial Number :%08lX ", backplane->serial_number); dprint(DEBUG_VALUES, "Backplane size :%d\n", backplane->rack_size); } who(comm, rack, NULL, debug); path->device1 = 1; path->device2 = rack->cpulocation; path->device3 = -1; path->device4 = -1; path->device5 = -1; path->device6 = -1; path->device7 = -1; path->device8 = -1; get_object_config_list(comm, path, 0, configtags, debug); get_object_details_list(comm, path, 0, detailtags, debug); get_program_list(comm, path, progs, debug); /* get_struct_list(comm, path, structs, debug); printf ("Got %d structs in the program.\n",structs->count); for (x=0;x<structs->count; x++) { printf ("Struct #%02d, type id = %08lX\n",x,structs->base[x]->base); get_struct_config (comm, path, structs->base[x], debug); get_struct_details (comm, path, structs->base[x], debug); printf ("Element count = %d Detail size = %d\n",structs->base[x]->count, structs->base[x]->detailsize); printf ("Element link-id = %04X\n",structs->base[x]->linkid); printf ("Structure base name = %s\n",structs->base[x]->name); for (y=0;y<structs->base[x]->count;y++) { printf ("Element #%d, type = %04X, arraysize = %d name = %s\n",y,structs->base[x]->data[y]->type, structs->base[x]->data[y]->arraysize, structs->base[x]->data[y]->name); } printf ("----------------------------------------\n"); } exit; */ y = detailtags->count; if (configtags->count > y) y = configtags->count; printf("Reading tags from ControlLogix...\n"); for (z = 0; z < y; z++) { if (z < detailtags->count) get_object_details(comm, path, detailtags->tag[z], debug); if (z < configtags->count) get_object_config(comm, path, configtags->tag[z], debug); printf ("%08lX - %08lX - %08lX - %08lX - %04X - %04X - %04X - %s - %ld - %ld - %ld - %ld\n", detailtags->tag[z]->topbase, detailtags->tag[z]->base, detailtags->tag[z]->id, detailtags->tag[z]->linkid, detailtags->tag[z]->size, detailtags->tag[z]->type, detailtags->tag[z]->alias_type, detailtags->tag[z]->name, detailtags->tag[z]->alias_linkid - detailtags->tag[z]->linkid, detailtags->tag[z]->arraysize1, detailtags->tag[z]->arraysize2, detailtags->tag[z]->arraysize3); } printf("Checking for aliases...\n"); for (z = 0; z < detailtags->count; z++) aliascheck(detailtags->tag[z], NULL, detailtags, DEBUG_VALUES); for (z = 0; z < y; z++) { if (z < detailtags->count) { switch (detailtags->tag[z]->type & 255) { case 0x68: case 0x69: break; default: read_object_value(comm, path, detailtags->tag[z], debug); } if (detailtags->tag[z]->topbase != 0) c1++; if (z < detailtags->count) { printf ("%08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %04lX - %04X - %04X - %s - %ld - %ld - %ld - %ld\n", detailtags->tag[z]->topbase, detailtags->tag[z]->base, detailtags->tag[z]->id, detailtags->tag[z]->linkid, detailtags->tag[z]->alias_topbase, detailtags->tag[z]->alias_base, detailtags->tag[z]->alias_id, detailtags->tag[z]->type, detailtags->tag[z]->alias_type, detailtags->tag[z]->name, detailtags->tag[z]->alias_linkid - detailtags->tag[z]->linkid, detailtags->tag[z]->arraysize1, detailtags->tag[z]->arraysize2, detailtags->tag[z]->arraysize3); } if (z < configtags->count) { printf("%08lX - %08lX - %04X\n", configtags->tag[z]->topbase, configtags->tag[z]->linkid, configtags->tag[z]->type); } /* if (strncmp ( detailtags->tag[z]->name, "IntArray",strlen(detailtags->tag[z]->name))) { read_object_value(comm, path, detailtags->tag[z], debug); printf ("Old:\n"); for (x=0;x<detailtags->tag[z]->datalen;x++) printf ("%02X ",detailtags->tag[z]->data[x]); printf ("\n"); for (x=0;x<detailtags->tag[z]->datalen; x++) detailtags->tag[z]->data[x]++; write_object_value(comm, path, detailtags->tag[z], 4); read_object_value(comm, path, detailtags->tag[z], debug); printf ("New:\n"); for (x=0;x<detailtags->tag[z]->datalen;x++) printf ("%02X ",detailtags->tag[z]->data[x]); printf ("\n"); } */ } } /* for (z = 0; z < y; z+=5) { if (z < detailtags->count) { switch (detailtags->tag[z]->type & 255) { case 0x68: case 0x69: break; default: list->count = 1; list->tag[0] = detailtags->tag[z]; if (z+1 < y) list->tag[list->count++] = detailtags->tag[z+1]; if (z+2 < y) list->tag[list->count++] = detailtags->tag[z+2]; if (z+3 < y) list->tag[list->count++] = detailtags->tag[z+3]; if (z+4 < y) list->tag[list->count++] = detailtags->tag[z+4]; read_multi_object_value(comm, path, list, debug); } } } */ for (z=0; z<detailtags->count; z++) { printf ("%s : ",detailtags->tag[z]->name); for (x=0;x<detailtags->tag[z]->datalen;x++) printf ("%02X ",detailtags->tag[z]->data[x]); printf ("\n"); } //exit(0); printf("%d objects with topbase != 0.\n", c1); printf("%d objects type 0x68, %d objects type 0x69.\n", c68, c69); printf("configtags count = %d detailtags count = %d\n", configtags->count, detailtags->count); printf("Got %d programs...\n", progs->count); for (x = 0; x < progs->count; x++) { program_tags[x] = malloc(sizeof(_tag_data)); if (program_tags[x] == NULL) { printf("Could not allocate memory for program tag structure.\n"); exit(-1); } get_program_details(comm, path, progs->prog[x], debug); for (y = 0; y < detailtags->count; y++) { if (detailtags->tag[y]->linkid == progs->prog[x]->linkid) { strcpy(progs->prog[x]->name, detailtags->tag[y]->name); } } printf("id for program #%d is %08lX link ID = %08lX - %s\n", x, progs->prog[x]->base, progs->prog[x]->linkid, progs->prog[x]->name); } for (x = 0; x < progs->count; x++) { if (quiet == FALSE) printf("Tag list for %s\n", progs->prog[x]->name); get_object_details_list(comm, path, progs->prog[x]->base, program_tags[x], debug); printf("tag count = %d\n\n", program_tags[x]->count); for (y = 0; y < program_tags[x]->count; y++) { get_object_details(comm, path, program_tags[x]->tag[y], debug); /* aliascheck(program_tags[x]->tag[y], program_tags[x], detailtags, DEBUG_VALUES); if (quiet == FALSE) printf("%08lX %08lX %08lX %08lX ", program_tags[x]->tag[y]->topbase, program_tags[x]->tag[y]->base, program_tags[x]->tag[y]->id, program_tags[x]->tag[y]->linkid); if (quiet == FALSE) { printf("type = %04X Name = %s\n", program_tags[x]->tag[y]->type, program_tags[x]->tag[y]->name); printf("arraysize1 = %ld arraysize2 = %ld arraysize3 = %ld\n", program_tags[x]->tag[y]->arraysize1, program_tags[x]->tag[y]->arraysize2, program_tags[x]->tag[y]->arraysize3); } */ } if (quiet == FALSE) printf("-----------------------------------\n"); } for (x = 0; x < detailtags->count; x++) { if ((detailtags->tag[x]->size != 0) || (detailtags->tag[x]->alias_size != 0)) { result = read_object_value(comm, path, detailtags->tag[x], debug); if (result != 0) { printf("Got non-zero return from read_object_value - %02X\n", result); printf ("%08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %04X - %s - %ld - %ld - %ld\n", detailtags->tag[x]->topbase, detailtags->tag[x]->base, detailtags->tag[x]->id, detailtags->tag[x]->linkid, detailtags->tag[x]->alias_topbase, detailtags->tag[x]->alias_base, detailtags->tag[x]->alias_id, detailtags->tag[x]->type, detailtags->tag[x]->name, detailtags->tag[x]->arraysize1, detailtags->tag[x]->arraysize2, detailtags->tag[x]->arraysize3); } if (quiet == FALSE) { printf("Value(s) for %s: ", detailtags->tag[x]->name); for (y = 0; y < detailtags->tag[x]->size; y++) printf("%02X ", detailtags->tag[x]->data[y]); printf("\n"); } } } for (x = 0; x < progs->count; x++) { if (quiet == FALSE) printf("Reading %d Data Values for program %s tags...\n", program_tags[x]->count, progs->prog[x]->name); for (y = 0; y < program_tags[x]->count; y++) { if ((program_tags[x]->tag[y]->type & 255) > 0xbf) { read_object_value(comm, path, program_tags[x]->tag[y], debug); if (quiet == FALSE) { printf("Value(s) for %s: ", program_tags[x]->tag[y]->name); for (z = 0; z < program_tags[x]->tag[y]->datalen; z++) printf("%02X ", program_tags[x]->tag[y]->data[z]); printf("\n"); } } if (quiet == FALSE) printf("---------------------------------\n"); } } closesocket(comm->file_handle); exit(0); }
//void main_function(cyg_addrword_t data) { void * main_function(void * data) { int tmp = 1; region_information = (int *) malloc (4 * sizeof(int)); // create particles create_particle_filter(100, 10); /*slots = (int *) malloc (6 * sizeof(int)); slots[0] = 0; slots[1] = 1; slots[2] = 2; slots[3] = 3; slots[4] = 4; slots[5] = 5; set_importance_hw_static(1, &slots[0]);*/ /*rthread_attr_init(&hwthread_sorter_attr); rthread_attr_setslotnum(&hwthread_sorter_attr, 0); rthread_attr_setresources(&hwthread_sorter_attr, hwthread_sorter_resources, 3); reconos_hwthread_create( 15, // priority &hwthread_sorter_attr, // hardware thread attributes 0, // entry data (not needed) "MT_HW_SORT", // thread name hwthread_sorter_stack, // stack STACK_SIZE, // stack size &hwthread_sorter_handle, // thread handle &hwthread_sorter // thread object ); cyg_thread_resume( hwthread_sorter_handle );*/ //cyg_thread_delay(50); #ifndef NO_ETHERNET init_all_network_interfaces(); if(!eth0_up){ printf("failed to initialize eth0\naborting\n"); return NULL; } else{ printf(" eth0 up\n"); } diag_printf( "initializing ECAP interface..." ); ecap_init(); diag_printf( "done\n" ); // establish connection while (tmp == 1){ tmp = establish_connection(6666, region_information); } #endif // start read_new_frame cyg_semaphore_post(sem_read_new_frame_start); srand(1); // set region information for equal time measurements #define VIDEO 1 printf("\n#################################################"); printf("\n#################################################"); #ifdef VIDEO #if VIDEO==1 printf("\n########## S O C C E R V I D E O ############"); region_information[0] = 286; region_information[1] = 247; region_information[2] = 117; region_information[3] = 171; #else #if VIDEO==2 printf("\n######## F O O T B A L L V I D E O ##########"); region_information[0] = 255; region_information[1] = 252; region_information[2] = 23; region_information[3] = 41; #else #if VIDEO==3 printf("\n########## H O C K E Y V I D E O ############"); region_information[0] = 152; region_information[1] = 95; region_information[2] = 19; region_information[3] = 39; #else #if VIDEO==4 printf("\n########## H O C K E Y V I D E O (FULL PICTURE) ############"); region_information[0] = 159; region_information[1] = 119; region_information[2] = 320; region_information[3] = 240; #endif #endif #endif #endif #else printf("\n###### N O V I D E O D E F I N E D ########"); #endif printf("\n#################################################"); printf("\n#################################################\n"); // init particles init_particles(region_information, 4); // Output Object Region printf("\n\nx0 = %d\ny0 = %d\nwidth = %d\nheight = %d\n\n", region_information[0], region_information[1], region_information[2], region_information[3]); particle p; p.x = region_information[0]*PF_GRANULARITY; p.y = region_information[1]*PF_GRANULARITY; p.x0 = p.x; p.y0 = p.y; p.xp = p.x; p.yp = p.y; p.s = PF_GRANULARITY; p.sp = p.s; p.width = region_information[2]; p.height = region_information[3]; // get reference data get_reference_data(&p, &reference_data); init_reference_data (&reference_data); print_histogram(&reference_data); //print_histogram2(&reference_data); #ifdef STORE_VIDEO int i; printf("\n\nThe first %d Frames will be stored into Main Memory. Again this will take some time.\n", (int)MAX_FRAMES); // load first frames for(i=0; i<MAX_FRAMES-1; i++){ //switch_framebuffer(); read_frame(); } printf("\nFinished: The first %d Frames are stored in the Main Memory.\n", (int)MAX_FRAMES); #endif parameter_s = (int *) malloc (5 * sizeof(int)); parameter_s[0] = SIZE_X; parameter_s[1] = SIZE_Y; parameter_s[2] = 16384; // GRANULARITY / TRANS_STD_X parameter_s[3] = 8192; // GRANULARITY / TRANS_STD_Y parameter_s[4] = 16; // GRANULARITY / TRANS_STD_S parameter_o = (int *) malloc (2 * sizeof(int)); parameter_o[0] = SIZE_X; parameter_o[1] = SIZE_Y; slots = (int *) malloc (6 * sizeof(int)); slots[0] = 0; slots[1] = 1; slots[2] = 2; slots[3] = 3; slots[4] = 4; slots[5] = 5; // create sampling, importance, resampling thread printf("\n#################################################"); printf("\n#################################################"); #ifdef PARTITIONING #if PARTITIONING==1 printf("\n###### P A R T I T I O N I N G S W #######"); set_sample_sw(1); set_observe_sw(1); set_importance_sw(1); set_resample_sw(1); #else #if PARTITIONING==2 printf("\n#### P A R T I T I O N I N G H W I #####"); set_sample_sw(1); set_observe_sw(1); set_importance_sw(1); set_importance_hw_static(1, &slots[2]); set_resample_sw(1); #else #if PARTITIONING==3 printf("\n#### P A R T I T I O N I N G H W II #####"); set_sample_sw(1); set_observe_sw(1); set_importance_sw(1); set_importance_hw_static(2, &slots[2]); set_resample_sw(1); #else #if PARTITIONING==4 printf("\n#### P A R T I T I O N I N G H W O #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(1, &slots[0], parameter_o, 2); set_importance_sw(1); set_resample_sw(1); #else #if PARTITIONING==5 printf("\n#### P A R T I T I O N I N G H W OO #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(1, &slots[0], parameter_o, 2); set_importance_sw(1); set_resample_sw(1); #else #if PARTITIONING==6 printf("\n#### P A R T I T I O N I N G H W IO #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(1, &slots[0], parameter_o, 2); set_importance_sw(1); set_importance_hw_static(1, &slots[2]); set_resample_sw(1); #else #if PARTITIONING==7 printf("\n#### P A R T I T I O N I N G H W IIO #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(2, &slots[0], parameter_o, 2); set_importance_sw(1); set_importance_hw_static(1, &slots[2]); set_resample_sw(1); #else #if PARTITIONING==8 printf("\n#### P A R T I T I O N I N G H W IOO #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(1, &slots[0], parameter_o, 2); set_importance_sw(1); set_importance_hw_static(2, &slots[2]); set_resample_sw(1); #else #if PARTITIONING==9 printf("\n#### P A R T I T I O N I N G H W IIOO #####"); set_sample_sw(1); set_observe_sw(1); set_observe_hw_static(2, &slots[0], parameter_o, 2); set_importance_sw(1); set_importance_hw_static(2, &slots[2]); set_resample_sw(1); #endif #endif #endif #endif #endif #endif #endif #endif #endif #else //printf("\n# N O P A R T I T I O N I N G D E F I N E D #"); printf("\n#### P A R T I T I O N I N G S W O #####"); reconf_mode_observation_on = TRUE; reconf_mode_observation_last_slot_on = FALSE; // I. SAMPLING //////////////////////////////////////// set_sample_sw(1); //set_sample_hw_dynamic(1, &hw_thread_s_circuit, parameter_s, 5); // II. OBSERVATION //////////////////////////////////// //set_observe_sw(1); set_observe_hw_dynamic(2, &hw_thread_o_circuit, parameter_o, 2); //set_observe_hw_dynamic(2, &hw_thread_o_circuit, parameter_o, 2); //set_observe_hw_static(1, &slots[2], parameter_o, 2); // III. IMPORTANCE //////////////////////////////////// set_importance_sw(1); //set_importance_hw_dynamic(1, &hw_thread_i_circuit); //set_importance_hw_dynamic(2, &hw_thread_i_circuit); set_importance_hw_static(1, &slots[2]); //[2] // IV. RESAMPLING ///////////////////////////////////// set_resample_sw(1); #endif printf("\n#################################################"); printf("\n#################################################\n"); /* // create and start sorting thread init_all_network_interfaces(); if(!eth0_up){ printf("failed to initialize eth0\naborting\n"); return NULL; } else{ printf(" eth0 up\n"); } diag_printf( "initializing ECAP interface..." ); ecap_init(); diag_printf( "done\n" );*/ //create_particle_filter(100, 10); //set_observe_hw_dynamic(2, &hw_thread_o_circuit, 0, 0); //sw_test_thread = (cyg_thread *) malloc (sizeof(cyg_thread)); //sw_test_thread_stack = (char *) malloc (sizeof(char) * STACK_SIZE); //sw_test_thread_handle = (cyg_handle_t *) malloc(sizeof(cyg_handle_t)); /*cyg_thread_create(PRIO, // scheduling info (eg pri) test_thread, // entry point function 0, // entry data "TEST", // optional thread name //sw_test_thread_stack, // stack base sw_measurement_thread_4_stack, // stack base STACK_SIZE, // stack size, //sw_test_thread_handle, // returned thread handle &sw_measurement_thread_4_handle, // returned thread handle //sw_test_thread // put thread here &sw_measurement_thread_4 // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_4_handle);*/ //cyg_thread_resume(*sw_test_thread_handle); /*cyg_thread_create(PRIO, // scheduling info (eg pri) test_thread, // entry point function 0, // entry data "READ_MEASUREMENTS_4", // optional thread name sw_measurement_thread_4_stack, // stack base STACK_SIZE, // stack size, &sw_measurement_thread_4_handle, // returned thread handle &sw_measurement_thread_4 // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_4_handle);*/ //cyg_thread_delay(1000); //diag_printf( "Reconfigure!\n" ); /*old_number_of_sortings = 0; start_sorting(); set_sort8k_hw_dynamicB(2); set_sort8k_hw_dynamic(2); cyg_thread_delay(1000);*/ start_particle_filter(); printf("\nstart particle filter"); return NULL; }
/*---------------------------------------------------------------------------*/ int run_client_test(struct perf_parameters *user_param) { struct session_data sess_data; struct perf_comm *comm; struct thread_data *tdata; char url[256]; int i = 0; int max_cpus; pthread_t statistics_thread_id; struct perf_command command; int size_log2; int max_size_log2 = 24; /* client session attributes */ struct xio_session_attr attr = { &ses_ops, NULL, 0 }; xio_init(); g_mhz = get_cpu_mhz(0); max_cpus = sysconf(_SC_NPROCESSORS_ONLN); threads_iter = 1; size_log2 = 0; tdata = calloc(user_param->threads_num, sizeof(*tdata)); if (tdata == NULL) { fprintf(fd, "malloc failed\n"); return -1; } comm = create_comm_struct(user_param); if (establish_connection(comm)) { fprintf(stderr, "failed to establish connection\n"); free(tdata); destroy_comm_struct(comm); return -1; } if (user_param->output_file) { fd = fopen(user_param->output_file, "w"); if (fd == NULL) { fprintf(fd, "file open failed. %s\n", user_param->output_file); free(sess_data.tdata); destroy_comm_struct(comm); return -1; } fprintf(fd, "size, threads, tps, bw[Mbps], lat[usec]\n"); fflush(fd); } printf("%s", RESULT_FMT); printf("%s", RESULT_LINE); while (threads_iter <= user_param->threads_num) { data_len = (uint64_t)1 << size_log2; memset(&sess_data, 0, sizeof(sess_data)); memset(tdata, 0, user_param->threads_num*sizeof(*tdata)); sess_data.tdata = tdata; command.test_param.machine_type = user_param->machine_type; command.test_param.test_type = user_param->test_type; command.test_param.verb = user_param->verb; command.test_param.data_len = data_len; command.command = GetTestParams; ctx_write_data(comm, &command, sizeof(command)); sprintf(url, "rdma://%s:%d", user_param->server_addr, user_param->server_port); sess_data.session = xio_session_create(XIO_SESSION_CLIENT, &attr, url, 0, 0, &sess_data); if (sess_data.session == NULL) { int error = xio_errno(); fprintf(stderr, "session creation failed. reason %d - (%s)\n", error, xio_strerror(error)); goto cleanup; } pthread_create(&statistics_thread_id, NULL, statistics_thread_cb, &sess_data); /* spawn threads to handle connection */ for (i = 0; i < threads_iter; i++) { sess_data.tdata[i].affinity = ((user_param->cpu + i) % max_cpus); sess_data.tdata[i].cid = i; sess_data.tdata[i].sdata = &sess_data; sess_data.tdata[i].user_param = user_param; sess_data.tdata[i].data_len = data_len; /* all threads are working on the same session */ sess_data.tdata[i].session = sess_data.session; pthread_create(&sess_data.tdata[i].thread_id, NULL, worker_thread, &sess_data.tdata[i]); } pthread_join(statistics_thread_id, NULL); /* join the threads */ for (i = 0; i < threads_iter; i++) pthread_join(sess_data.tdata[i].thread_id, NULL); /* close the session */ xio_session_destroy(sess_data.session); if (sess_data.abort) { fprintf(stderr, "program aborted\n"); goto cleanup; } /* send result to server */ command.results.bytes = data_len; command.results.threads = threads_iter; command.results.tps = sess_data.tps; command.results.avg_bw = sess_data.avg_bw; command.results.avg_lat = sess_data.avg_lat_us; command.results.min_lat = sess_data.min_lat_us; command.results.max_lat = sess_data.max_lat_us; command.command = GetTestResults; /* sync point */ ctx_write_data(comm, &command, sizeof(command)); printf(REPORT_FMT, data_len, threads_iter, sess_data.tps, sess_data.avg_bw, sess_data.avg_lat_us, sess_data.min_lat_us, sess_data.max_lat_us); if (fd) fprintf(fd, "%lu, %d, %lu, %.2lf, %.2lf\n", data_len, threads_iter, sess_data.tps, sess_data.avg_bw, sess_data.avg_lat_us); fflush(fd); /* sync point */ ctx_read_data(comm, NULL, 0, NULL); if (++size_log2 < max_size_log2) continue; threads_iter++; size_log2 = 0; } printf("%s", RESULT_LINE); cleanup: if (fd) fclose(fd); ctx_hand_shake(comm); ctx_close_connection(comm); destroy_comm_struct(comm); free(tdata); xio_shutdown(); return 0; }
/* * Send the current request, after encrypting it. Returns 0 on success, * or -1 on failure. */ static int send_msg(struct tac_handle *h) { struct timeval deadline; struct tac_msg *msg; char *ptr; int len; if (h->last_seq_no & 1) { generr(h, "Attempt to send message out of sequence"); return -1; } if (establish_connection(h) == -1) return -1; msg = &h->request; msg->seq_no = ++h->last_seq_no; if (msg->seq_no == 1) gen_session_id(msg); crypt_msg(h, msg); if (h->single_connect) msg->flags |= TAC_SINGLE_CONNECT; else msg->flags &= ~TAC_SINGLE_CONNECT; gettimeofday(&deadline, NULL); deadline.tv_sec += h->servers[h->cur_server].timeout; len = HDRSIZE + ntohl(msg->length); ptr = (char *)msg; while (len > 0) { int n; n = write(h->fd, ptr, len); if (n == -1) { struct timeval tv; int nfds; if (errno != EAGAIN) { generr(h, "Network write error: %s", strerror(errno)); return -1; } /* Wait until we can write more data. */ gettimeofday(&tv, NULL); timersub(&deadline, &tv, &tv); if (tv.tv_sec >= 0) { fd_set wfds; FD_ZERO(&wfds); FD_SET(h->fd, &wfds); nfds = select(h->fd + 1, NULL, &wfds, NULL, &tv); if (nfds == -1) { generr(h, "select: %s", strerror(errno)); return -1; } } else nfds = 0; if (nfds == 0) { generr(h, "Network write timed out"); return -1; } } else { ptr += n; len -= n; } } return 0; }
int main(int argc, char *argv[]) { struct ibv_device *ib_dev; struct pingpong_context ctx; struct pingpong_dest *my_dest,*rem_dest; struct perftest_parameters user_param; struct perftest_comm user_comm; int i = 0; memset(&ctx,0,sizeof(struct pingpong_context)); memset(&user_param, 0, sizeof(struct perftest_parameters)); memset(&user_comm,0,sizeof(struct perftest_comm)); user_param.verb = WRITE; user_param.tst = BW; user_param.spec = PL; user_param.version = VERSION; // Configure the parameters values according to user arguments or defalut values. if (parser(&user_param,argv,argc)) { fprintf(stderr," Parser function exited with Error\n"); return 1; } // Finding the IB device selected (or defalut if no selected). ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE deivce\n"); return 1; } // Getting the relevant context from the device ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } // See if MTU and link type are valid and supported. if (check_link_and_mtu(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } // Print basic test information. ctx_print_test_info(&user_param); ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps); memset(my_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); ALLOCATE(rem_dest , struct pingpong_dest , user_param.num_of_qps); memset(rem_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); // copy the rellevant user parameters to the comm struct + creating rdma_cm resources. if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } // Create (if nessacery) the rdma_cm ids and channel. if (user_param.work_rdma_cm == ON) { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (user_param.machine == CLIENT) { if (rdma_client_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { // create all the basic IB resources (data buffer, PD, MR, CQ and events channel) if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } // Set up the Connection. if (set_up_connection(&ctx,&user_param,my_dest)) { fprintf(stderr," Unable to set up socket connection\n"); return FAILURE; } // Print this machine QP information for (i=0; i < user_param.num_of_qps; i++) ctx_print_pingpong_data(&my_dest[i],&user_comm); // Init the connection and print the local data. if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return FAILURE; } // shaking hands and gather the other side info. for (i=0; i < user_param.num_of_qps; i++) { if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr," Failed to exchange date between server and clients\n"); return 1; } // Print remote machine QP information user_comm.rdma_params->side = REMOTE; ctx_print_pingpong_data(&rem_dest[i],&user_comm); if (user_param.work_rdma_cm == OFF) { if (pp_connect_ctx(&ctx,my_dest[i].psn,&rem_dest[i],&user_param,i)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return FAILURE; } } // An additional handshake is required after moving qp to RTR. if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr," Failed to exchange date between server and clients\n"); return FAILURE; } } printf(RESULT_LINE); printf(RESULT_FMT); // For half duplex tests, server just waits for client to exit if (user_param.machine == SERVER && !user_param.duplex) { if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } printf(RESULT_LINE); return 0; } ALLOCATE(tposted,cycles_t,user_param.iters*user_param.num_of_qps); ALLOCATE(tcompleted,cycles_t,user_param.iters*user_param.num_of_qps); if (user_param.all == ON) { for (i = 1; i < 24 ; ++i) { user_param.size = 1 << i; if(run_iter(&ctx,&user_param,rem_dest)) return 17; print_report(&user_param); } } else { if(run_iter(&ctx,&user_param,rem_dest)) return 18; print_report(&user_param); } free(tposted); free(tcompleted); // Closing connection. if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to close connection between server and client\n"); return 1; } free(my_dest); free(rem_dest); printf(RESULT_LINE); return 0; }
int main(int argc, char *argv[]) { struct ibv_device *ib_dev = NULL; struct pingpong_context ctx; struct pingpong_dest *my_dest = NULL; struct pingpong_dest *rem_dest = NULL; struct perftest_parameters user_param; struct perftest_comm user_comm; struct mcast_parameters mcg_params; struct bw_report_data my_bw_rep, rem_bw_rep; int ret_parser,i = 0; int size_max_pow = 24; /* init default values to user's parameters */ memset(&ctx, 0,sizeof(struct pingpong_context)); memset(&user_param, 0 , sizeof(struct perftest_parameters)); memset(&mcg_params, 0 , sizeof(struct mcast_parameters)); memset(&user_comm, 0,sizeof(struct perftest_comm)); user_param.verb = SEND; user_param.tst = BW; strncpy(user_param.version, VERSION, sizeof(user_param.version)); /* Configure the parameters values according to user arguments or defalut values. */ ret_parser = parser(&user_param,argv,argc); if (ret_parser) { if (ret_parser != VERSION_EXIT && ret_parser != HELP_EXIT) fprintf(stderr," Parser function exited with Error\n"); return 1; } if((user_param.connection_type == DC || user_param.use_xrc) && user_param.duplex) { user_param.num_of_qps *= 2; } /* Checking that the user did not run with RawEth. for this we have raw_etherent_bw test. */ if (user_param.connection_type == RawEth) { fprintf(stderr," This test cannot run Raw Ethernet QPs (you have chosen RawEth as connection type\n"); fprintf(stderr," For this we have raw_ethernet_bw test in this package.\n"); return FAILURE; } /* Finding the IB device selected (or defalut if no selected). */ ib_dev = ctx_find_dev(user_param.ib_devname); if (!ib_dev) { fprintf(stderr," Unable to find the Infiniband/RoCE device\n"); return 1; } if (user_param.use_mcg) GET_STRING(mcg_params.ib_devname,ibv_get_device_name(ib_dev)); /* Getting the relevant context from the device */ ctx.context = ibv_open_device(ib_dev); if (!ctx.context) { fprintf(stderr, " Couldn't get context for the device\n"); return 1; } /* See if MTU and link type are valid and supported. */ if (check_link(ctx.context,&user_param)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } /* copy the relevant user parameters to the comm struct + creating rdma_cm resources. */ if (create_comm_struct(&user_comm,&user_param)) { fprintf(stderr," Unable to create RDMA_CM resources\n"); return 1; } if (user_param.output == FULL_VERBOSITY && user_param.machine == SERVER) { printf("\n************************************\n"); printf("* Waiting for client to connect... *\n"); printf("************************************\n"); } /* Initialize the connection and print the local data. */ if (establish_connection(&user_comm)) { fprintf(stderr," Unable to init the socket connection\n"); return FAILURE; } exchange_versions(&user_comm, &user_param); check_sys_data(&user_comm, &user_param); /* See if MTU and link type are valid and supported. */ if (check_mtu(ctx.context,&user_param, &user_comm)) { fprintf(stderr, " Couldn't get context for the device\n"); return FAILURE; } /* Print basic test information. */ ctx_print_test_info(&user_param); ALLOCATE(my_dest , struct pingpong_dest , user_param.num_of_qps); memset(my_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); ALLOCATE(rem_dest , struct pingpong_dest , user_param.num_of_qps); memset(rem_dest, 0, sizeof(struct pingpong_dest)*user_param.num_of_qps); if (user_param.transport_type == IBV_TRANSPORT_IWARP) ctx.send_rcredit = 1; /* Allocating arrays needed for the test. */ alloc_ctx(&ctx,&user_param); /* Create (if nessacery) the rdma_cm ids and channel. */ if (user_param.work_rdma_cm == ON) { if (user_param.machine == CLIENT) { if (retry_rdma_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } else { if (create_rdma_resources(&ctx,&user_param)) { fprintf(stderr," Unable to create the rdma_resources\n"); return FAILURE; } if (rdma_server_connect(&ctx,&user_param)) { fprintf(stderr,"Unable to perform rdma_client function\n"); return FAILURE; } } } else { /* create all the basic IB resources (data buffer, PD, MR, CQ and events channel) */ if (ctx_init(&ctx,&user_param)) { fprintf(stderr, " Couldn't create IB resources\n"); return FAILURE; } } /* Set up the Connection. */ if (send_set_up_connection(&ctx,&user_param,my_dest,&mcg_params,&user_comm)) { fprintf(stderr," Unable to set up socket connection\n"); return 1; } if (ctx.send_rcredit) ctx_alloc_credit(&ctx,&user_param,my_dest); for (i=0; i < user_param.num_of_qps; i++) ctx_print_pingpong_data(&my_dest[i],&user_comm); user_comm.rdma_params->side = REMOTE; for (i=0; i < user_param.num_of_qps; i++) { /* shaking hands and gather the other side info. */ if (ctx_hand_shake(&user_comm,&my_dest[i],&rem_dest[i])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } ctx_print_pingpong_data(&rem_dest[i],&user_comm); } if (user_param.work_rdma_cm == OFF) { if (ctx_check_gid_compatibility(&my_dest[0], &rem_dest[0])) { fprintf(stderr,"\n Found Incompatibility issue with GID types.\n"); fprintf(stderr," Please Try to use a different IP version.\n\n"); return 1; } } /* If credit for available recieve buffers is necessary, * the credit sending is done via RDMA WRITE ops and the ctx_hand_shake above * is used to exchange the rkeys and buf addresses for the RDMA WRITEs */ if (ctx.send_rcredit) ctx_set_credit_wqes(&ctx,&user_param,rem_dest); /* Joining the Send side port the Mcast gid */ if (user_param.use_mcg && (user_param.machine == CLIENT || user_param.duplex)) { memcpy(mcg_params.mgid.raw, rem_dest[0].gid.raw, 16); if (set_mcast_group(&ctx,&user_param,&mcg_params)) { fprintf(stderr," Unable to Join Sender to Mcast gid\n"); return 1; } /* * The next stall in code (50 ms sleep) is a work around for fixing the * the bug this test had in Multicast for the past 1 year. * It appears, that when a switch involved, it takes ~ 10 ms for the join * request to propogate on the IB fabric, thus we need to wait for it. * what happened before this fix was client reaching the post_send * code segment in about 350 ns from here, and the switch(es) dropped * the packet because join request wasn't finished. */ usleep(50000); } if (user_param.work_rdma_cm == OFF) { /* Prepare IB resources for rtr/rts. */ if (ctx_connect(&ctx,rem_dest,&user_param,my_dest)) { fprintf(stderr," Unable to Connect the HCA's through the link\n"); return 1; } } /* shaking hands and gather the other side info. */ if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (user_param.use_event) { if (ibv_req_notify_cq(ctx.send_cq, 0)) { fprintf(stderr, " Couldn't request CQ notification\n"); return 1; } if (ibv_req_notify_cq(ctx.recv_cq, 0)) { fprintf(stderr, " Couldn't request CQ notification\n"); return 1; } } if (user_param.output == FULL_VERBOSITY) { if (user_param.report_per_port) { printf(RESULT_LINE_PER_PORT); printf((user_param.report_fmt == MBS ? RESULT_FMT_PER_PORT : RESULT_FMT_G_PER_PORT)); } else { printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); } printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); } if (user_param.test_method == RUN_ALL) { if (user_param.connection_type == UD) size_max_pow = (int)UD_MSG_2_EXP(MTU_SIZE(user_param.curr_mtu)) + 1; for (i = 1; i < size_max_pow ; ++i) { user_param.size = (uint64_t)1 << i; if (user_param.machine == CLIENT || user_param.duplex) ctx_set_send_wqes(&ctx,&user_param,rem_dest); if (user_param.machine == SERVER || user_param.duplex) { if (ctx_set_recv_wqes(&ctx,&user_param)) { fprintf(stderr," Failed to post receive recv_wqes\n"); return 1; } } if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (ctx.send_rcredit) { int j; for (j = 0; j < user_param.num_of_qps; j++) ctx.credit_buf[j] = 0; } if (user_param.duplex) { if(run_iter_bi(&ctx,&user_param)) return 17; } else if (user_param.machine == CLIENT) { if(run_iter_bw(&ctx,&user_param)) { return 17; } } else { if(run_iter_bw_server(&ctx,&user_param)) { return 17; } } print_report_bw(&user_param,&my_bw_rep); if (user_param.duplex && user_param.test_type != DURATION) { xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); print_full_bw_report(&user_param, &my_bw_rep, &rem_bw_rep); } if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } /* Check if last iteration ended well in UC/UD */ if (user_param.check_alive_exited) { break; } } } else if (user_param.test_method == RUN_REGULAR) { if (user_param.machine == CLIENT || user_param.duplex) ctx_set_send_wqes(&ctx,&user_param,rem_dest); if (user_param.machine == SERVER || user_param.duplex) { if (ctx_set_recv_wqes(&ctx,&user_param)) { fprintf(stderr," Failed to post receive recv_wqes\n"); return 1; } } if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (user_param.duplex) { if(run_iter_bi(&ctx,&user_param)) return 17; } else if (user_param.machine == CLIENT) { if(run_iter_bw(&ctx,&user_param)) { return 17; } } else if(run_iter_bw_server(&ctx,&user_param)) { return 17; } print_report_bw(&user_param,&my_bw_rep); if (user_param.duplex && user_param.test_type != DURATION) { xchg_bw_reports(&user_comm, &my_bw_rep,&rem_bw_rep,atof(user_param.rem_version)); print_full_bw_report(&user_param, &my_bw_rep, &rem_bw_rep); } if (user_param.report_both && user_param.duplex) { printf(RESULT_LINE); printf("\n Local results: \n"); printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); print_full_bw_report(&user_param, &my_bw_rep, NULL); printf(RESULT_LINE); printf("\n Remote results: \n"); printf(RESULT_LINE); printf((user_param.report_fmt == MBS ? RESULT_FMT : RESULT_FMT_G)); printf((user_param.cpu_util_data.enable ? RESULT_EXT_CPU_UTIL : RESULT_EXT)); print_full_bw_report(&user_param, &rem_bw_rep, NULL); } } else if (user_param.test_method == RUN_INFINITELY) { if (user_param.machine == CLIENT) ctx_set_send_wqes(&ctx,&user_param,rem_dest); else if (user_param.machine == SERVER) { if (ctx_set_recv_wqes(&ctx,&user_param)) { fprintf(stderr," Failed to post receive recv_wqes\n"); return 1; } } if (ctx_hand_shake(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr,"Failed to exchange data between server and clients\n"); return 1; } if (user_param.machine == CLIENT) { if(run_iter_bw_infinitely(&ctx,&user_param)) { fprintf(stderr," Error occured while running infinitely! aborting ...\n"); return 1; } } else if (user_param.machine == SERVER) { if(run_iter_bw_infinitely_server(&ctx,&user_param)) { fprintf(stderr," Error occured while running infinitely on server! aborting ...\n"); return 1; } } } if (user_param.output == FULL_VERBOSITY) { if (user_param.report_per_port) printf(RESULT_LINE_PER_PORT); else printf(RESULT_LINE); } if (ctx_close_connection(&user_comm,&my_dest[0],&rem_dest[0])) { fprintf(stderr," Failed to close connection between server and client\n"); fprintf(stderr," Trying to close this side resources\n"); } /* Destory all test resources, including Mcast if exists */ if (send_destroy_ctx(&ctx,&user_param,&mcg_params)) { fprintf(stderr,"Couldn't Destory all SEND resources\n"); return FAILURE; } if (user_param.work_rdma_cm == ON) { user_comm.rdma_params->work_rdma_cm = ON; if (destroy_ctx(user_comm.rdma_ctx,user_comm.rdma_params)) { fprintf(stderr,"Failed to destroy resources\n"); return 1; } } if (!user_param.is_bw_limit_passed && (user_param.is_limit_bw == ON ) ) { fprintf(stderr,"Error: BW result is below bw limit\n"); return 1; } if (!user_param.is_msgrate_limit_passed && (user_param.is_limit_bw == ON )) { fprintf(stderr,"Error: Msg rate is below msg_rate limit\n"); return 1; } return 0; }