int main(int argc, char **argv) { int sock_fd; struct sockaddr_in client_addr; int client_addr_len; char recv_buff[INET_ADDRSTRLEN]; sock_fd = socket(AF_INET, SOCK_STREAM, 0); if (sock_fd < 0) { prerr("socket"); exit(1); } client_addr.sin_family = AF_INET; client_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); client_addr.sin_port = htons(8001); client_addr_len = sizeof(client_addr); int rtval; rtval = connect(sock_fd, (struct sockaddr *)&client_addr, client_addr_len); if(rtval == -1) { prerr("connect"); exit(1); } int rsnum; char *send_buf = "Client to Server string!\n"; rsnum = send(sock_fd, (void *)send_buf, strlen(send_buf), 0); if (rsnum < 0) { prerr("send"); exit(1); } printf("sent line:%s", send_buf); rsnum = recv(sock_fd, (void *)recv_buff, INET_ADDRSTRLEN, 0); if (rsnum < 0) { prerr("recv"); exit(1); } printf("readline:%s\t", recv_buff); printf("client exit.\n"); close(sock_fd); return 0; }
static void check(SQLRETURN ret, SQLSMALLINT tpe, SQLHANDLE hnd, const char *func) { switch (ret) { case SQL_SUCCESS: break; case SQL_SUCCESS_WITH_INFO: prerr(tpe, hnd, func, "Info"); break; case SQL_ERROR: prerr(tpe, hnd, func, "Error"); exit(1); case SQL_INVALID_HANDLE: fprintf(stderr, "%s: Error: invalid handle\n", func); exit(1); default: fprintf(stderr, "%s: Unexpected return value\n", func); break; } }
/* Set core specific TDMA bus schedule data in a segment */ static void set_core_specific_data(core_sched_p* head_core, int ncore, FILE* fp) { assert(head_core); int i; int delimiter; for(i = 0; i < ncore; i++) { CALLOC( head_core[i], core_sched_p, 1, sizeof(core_sched_s), "head_core[i]" ); fscanf(fp, "%Lu", &(head_core[i]->start_time)); fscanf(fp, "%u", &(head_core[i]->interval)); fscanf(fp, "%u", &(head_core[i]->slot_len)); fscanf(fp, "%u", &delimiter); if(delimiter > 0) prerr("Error: TDMA bus schedule file is in wrong format"); } }
/* * Traverse CFG in reverse topological order (already given in bblist) * to collect cost, eliminating infeasible paths. */ int traverse( int pid, block **bblist, int num_bb, int *in_degree, uint *cost ) { DSTART( "traverse" ); int i, j, k, id, pt; char direction, extend; path *pu, *pv; block *bu, *bv; branch *bru; for( i = 0; i < num_bb; i++ ) { bu = bblist[i]; bru = branchlist[pid][bu->bbid]; // printf( "Node %d cost %d: \n", bu->bbid, cost[bu->bbid] ); fflush( stdout ); // printBlock( bu ); if( !bu->num_outgoing ) { // bu is a sink // cost(bu) = { sum(bu) | sum(bu) is the sum of costs of each instruction in bu }; MALLOC( pu, path*, sizeof(path), "path" ); pu->cost = cost[bu->bbid]; pu->bb_len = 1; MALLOC( pu->bb_seq, int*, sizeof(int), "path bb_seq" ); pu->bb_seq[0] = bu->bbid; pu->branch_len = 0; pu->branch_eff = NULL; pu->branch_dir = NULL; num_paths[bu->bbid]++; REALLOC( pathlist[bu->bbid], path**, num_paths[bu->bbid] * sizeof(path*), "pathlist elm" ); pathlist[bu->bbid][ num_paths[bu->bbid]-1 ] = pu; continue; } // Step 1: Compute the WCET paths of each branch for( j = 0; j < bu->num_outgoing; j++ ) { id = getblock( bu->outgoing[j], bblist, 0, i-1 ); if( id == -1 ) prerr( "Block %d-%d not found.\n", pid, bu->outgoing[j] ); bv = bblist[id]; // printf( "out: " ); printBlock( bv ); for( pt = 0; pt < num_paths[bv->bbid]; pt++ ) { pv = pathlist[bv->bbid][pt]; // branches with potential conflict if( bru != NULL ) { direction = detectDirection( bru, bv ); // printf( "%d:%d->%d: dirn = %d\n", pid, bu->bbid, bv->bbid, direction ); /* * temporary disable conflict detection * // test BB conflicts if( BBconflictInPath( bru, direction, bv, pv, bblist, num_bb )) continue; */ } /* * temporary disable conflict detection * // test BA conflicts if( BAconflictInPath( bu, bv, pv, bblist, num_bb )) continue; */ // else, include this path for bu MALLOC( pu, path*, sizeof(path), "path" ); pu->bb_len = pv->bb_len + 1; pu->cost = pv->cost + cost[bu->bbid]; // extra cost if bu-->bv is a region transition //int rid; //if( regionmode ) { // if( bu->callpid != -1 ) // rid = procs[bu->callpid]->bblist[ procs[bu->callpid]->num_bb - 1 ]->regid; // if( bu->callpid == -1 || rid == -1 ) { // if( bu->regid != -1 && bv->regid != -1 && bu->regid != bv->regid ) { // printf( "region transition %d-%d(%d) --> %d-%d(%d) cost: %u\n", // bu->pid, bu->bbid, bu->regid, bv->pid, bv->bbid, bv->regid, regioncost[bv->regid] ); // fflush( stdout ); // pu->cost += regioncost[bv->regid]; // } // } // // region transition due to procedure call at end of bu // else { // if( rid != -1 && bv->regid != -1 && rid != bv->regid ) { // printf( "region transition %d-%d(%d) procedure return %d(%d) --> %d-%d(%d) cost: %u\n", // bu->pid, bu->bbid, bu->regid, bu->callpid, rid, // bv->pid, bv->bbid, bv->regid, regioncost[bv->regid] ); fflush( stdout ); // pu->cost += regioncost[bv->regid]; // } // } //} // end if( regionmode ) extend = 0; if( bru != NULL && hasIncomingConflict( bru, direction, bblist, i+1, num_bb )) extend = 1; pu->branch_len = pv->branch_len; if( extend ) pu->branch_len++; MALLOC( pu->bb_seq, int*, pu->bb_len * sizeof(int), "path bb_seq" ); MALLOC( pu->branch_eff, branch**, pu->branch_len * sizeof(branch*), "path branch_eff" ); MALLOC( pu->branch_dir, char*, pu->branch_len * sizeof(char), "path branch_dir" ); copySeq( pu, pv ); pu->bb_seq[ pu->bb_len - 1 ] = bu->bbid; if( extend ) sortedInsertBranch( pu, bru, direction ); num_paths[bu->bbid]++; REALLOC( pathlist[bu->bbid], path**, num_paths[bu->bbid] * sizeof(path*), "pathlist elm" ); pathlist[bu->bbid][ num_paths[bu->bbid]-1 ] = pu; } // end for paths of bv } // end for bu's children if( num_paths[bu->bbid] <= 0 ) prerr( "\nNo feasible path at %d-%d!\n\n", pid, bu->bbid ); // Step 2: Consolidate // if( edges e1, ..., en in subgraph(bu) are not conflicting with some predecessors ) // combine the two paths in cost(bu) if they only differ in term ei // Note that for each node bu, we keep a list of nodes conflicting with bu and can reach bu. // Step 2.1 Update incoming conflicts list: clear bu since it is already visited for( j = 0; j < procs[pid]->num_bb; j++ ) { bru = branchlist[pid][j]; if( bru != NULL && bru->in_conflict[bu->bbid] ) bru->num_active_incfs--; } // Step 2.2 Merge paths for( pt = 0; pt < num_paths[bu->bbid]; pt++ ) { pu = pathlist[bu->bbid][pt]; // check each branch in this path for expired conflicts k = 0; while( k < pu->branch_len ) { // remove if no more incoming conflict, or cancelled by assignment in bu if( !pu->branch_eff[k]->num_active_incfs || assignsTo( bu, pu->branch_eff[k]->deri_tree )) removeBranch( pu, k ); else k++; } } // end for paths // printf( "Consolidation: Decision cancelled over\n" ); fflush( stdout ); if( num_paths[bu->bbid] > 1 ) { // sort by increasing cost, then decreasing number of branches sortPath( pathlist[bu->bbid], num_paths[bu->bbid] ); for( pt = 0; pt < num_paths[bu->bbid] - 1; pt++ ) { pu = pathlist[bu->bbid][pt]; for( k = pt + 1; k < num_paths[bu->bbid]; k++ ) { pv = pathlist[bu->bbid][k]; // remove pu if its conflict list is a superset of pv's // (i.e. pu has less cost yet more conflicts than pv, thus cannot be wcet path) if( subsetConflict( pv, pu )) { pu->bb_len = -1; break; } } } // remove the marked paths (id: the index to overwrite) id = -1; for( pt = 0; pt < num_paths[bu->bbid]; pt++ ) { pu = pathlist[bu->bbid][pt]; if( pu->bb_len == -1 ) { freePath( bu->bbid, pt ); if( id == -1 ) id = pt; } else { if( id > -1 ) pathlist[bu->bbid][id++] = pu; } } if( id > -1 ) num_paths[bu->bbid] = id; } // stats if( num_paths[bu->bbid] > max_paths ) max_paths = num_paths[bu->bbid]; // free paths in nodes which are dead (i.e. already processed) for( j = 0; j < bu->num_outgoing; j++ ) in_degree[ bu->outgoing[j] ]--; // note that the node in top topo order is excluded for( j = 0; j < num_bb - 1; j++ ) { id = bblist[j]->bbid; if( in_degree[id] == 0 && pathFreed[id] == 0 ) { freePathsInNode( id ); pathFreed[id] = 1; } } DOUT( "Paths at %d-%d: %d\n", pid, bu->bbid, num_paths[bu->bbid] ); DACTION( for( pt = 0; pt < num_paths[bu->bbid]; pt++ ) printPath( pathlist[bu->bbid][pt] ); );