ff5e96911fff056b53d235b62a2d47b0ffd7477c
1 /******************************************
2 * File: nt_bench.c
3 * Purpose: benchmarks for NT.
4 **************************************************************
5 * FILE: nt_bench.c
6 *
7 * DESCRIPTION: netapi user space transport
8 * library test application : benchmarks
9 *
10 * REVISION HISTORY: rev 0.0.1
11 *
12 * Copyright (c) Texas Instruments Incorporated 2010-2011
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the
24 * distribution.
25 *
26 * Neither the name of Texas Instruments Incorporated nor the names of
27 * its contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *****************************************/
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <string.h>
48 #include <signal.h>
49 #include <pthread.h>
50 #include <sched.h>
52 #include "trie.h"
53 #include "string.h"
54 #include "netapi.h"
55 #include "pktio.h"
56 #include "net_test.h"
57 #include <ti/drv/sa/salld.h>
59 #if defined(DEVICE_K2H)
60 #include <ti/drv/qmss/device/k2h/src/qmss_device.c>
61 #include <ti/drv/cppi/device/k2h/src/cppi_device.c>
62 #elif defined (DEVICE_K2K)
63 #include <ti/drv/qmss/device/k2k/src/qmss_device.c>
64 #include <ti/drv/cppi/device/k2k/src/cppi_device.c>
65 #elif defined (DEVICE_K2L)
66 #include <ti/drv/qmss/device/k2l/src/qmss_device.c>
67 #include <ti/drv/cppi/device/k2l/src/cppi_device.c>
68 #elif defined (DEVICE_K2E)
69 #include <ti/drv/qmss/device/k2e/src/qmss_device.c>
70 #include <ti/drv/cppi/device/k2e/src/cppi_device.c>
71 #else /*Default */
72 #include <ti/drv/qmss/device/k2h/src/qmss_device.c>
73 #include <ti/drv/cppi/device/k2h/src/cppi_device.c>
74 #endif /* Device */
76 #define netapi_timing_start hplib_mUtilGetPmuCCNT
78 static int scnt=0;
79 static int QUIT=0;
80 static int XMIT=0;
81 static int CAP=0;
82 volatile int RESET=0; //to reset stats
84 __thread int our_core;
86 void benchmarks1(void);
87 void benchmarks2(Pktlib_HeapHandle h , int n_trials);
88 void benchmarks3(Pktlib_HeapHandle h , int n_trials);
90 //sig handler
91 void netTest_utilMySig(int x)
92 {
93 QUIT=1;
94 scnt+=1;
95 printf(">ifdma-test: recv'd signal %d cnt=%d\n",x,scnt);
96 if (scnt > 10) {printf(">ifdma-test: WARNING EXITING WITH PROPER SHUTDOWN, LUTS LEFT ACTIVE\n");exit(1);}
98 }
99 void recv_cb_net(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
100 PKTIO_METADATA_T meta[], int n_pkts,
101 uint64_t ts );
104 /*************debug********************/
105 void netTest_utilDumpDescr(unsigned long *p, int n)
106 {
107 printf("--------dump of descriptor %d %x\n", n, (int) p);
108 printf("> %x %x %x %x %x %x %x %x\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
109 printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
110 printf("-----------------------------\n");
111 }
112 void netTest_utilDumpHeader(unsigned long *p, int n, int a, int r)
113 {
114 printf("--------dump of header %d %x appID=%x flag1=%x\n", n, (int) p,a,r);
115 printf("> %0x %0x %0x %0x %0x %0x %0x %0x\n",
116 ntohl(p[0]),ntohl(p[1]),ntohl(p[2]),ntohl(p[3]),
117 ntohl(p[4]),ntohl(p[5]),ntohl(p[6]),ntohl(p[7]) );
118 #if 0
119 printf("> %x %x %x %x %x %x %x %x\n",p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]);
120 printf("> %x %x %x %x %x %x %x %x\n",p[16],p[17],p[18],p[19],p[20],p[21],p[22],p[23]);
121 printf("> %x %x %x %x %x %x %x %x\n",p[24],p[25],p[26],p[27],p[28],p[29],p[30],p[31]);
122 #endif
123 printf("-----------------------------\n");
124 }
125 /*****************************************/
128 unsigned long long CALIB=0;
129 unsigned long long calibrate_idle(void)
130 {
131 volatile unsigned long long at1;
132 volatile unsigned long long at2;
133 volatile unsigned long pt1;
134 volatile unsigned long pt2;
135 unsigned long long calib;
136 at1 = hplib_mUtilGetTimestamp();
137 pt1=netapi_timing_start();
138 for(;;)
139 {
140 pt2=netapi_timing_start() ;
141 if ((pt2-pt1) >= 100000) break;
142 }
143 at2 = hplib_mUtilGetTimestamp();
145 calib = ((unsigned long long) (pt2-pt1))/(at2-at1);
146 printf("calibrate: arm time=%lld -> arm cycles=%d calib=%lld\n", at2-at1, pt2-pt1, calib);
148 return calib;
149 }
151 /*******************************************
152 *************NETAPI OBJECTS***************
153 *****************************************/
154 static NETAPI_CFG_T our_netapi_default_cfg=
155 {
156 TUNE_NETAPI_PERM_MEM_SZ,
157 128, //start of packet offset for hw to place data on rx for default flow
158 TUNE_NETAPI_QM_CONFIG_MAX_DESC_NUM, //max number of descriptors in system
159 TUNE_NETAPI_NUM_GLOBAL_DESC, //total we will use
160 TUNE_NETAPI_DEFAULT_NUM_BUFFERS, //#descriptors+buffers in default heap
161 64, //#descriptors w/o buffers in default heap
162 TUNE_NETAPI_DEFAULT_BUFFER_SIZE+128+128, //size of buffers in default heap
163 128, //tail room
164 256, //extra room
165 0,
166 NULL
167 };
169 Pktlib_HeapHandle OurHeap; //default heap, used by producer
170 PKTIO_CFG_T netcp_rx_cfg={PKTIO_RX, PKTIO_NA, PKTIO_NA, 8};
171 PKTIO_CFG_T netcp_tx_cfg={PKTIO_TX, PKTIO_NA, PKTIO_NA, 12};
172 PKTIO_HANDLE_T * netcp_rx_chan;
173 PKTIO_HANDLE_T * netcp_tx_chan;
174 NETAPI_T netapi_handle;
176 PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL};
177 PKTIO_CONTROL_T poll_cannel_control={PKTIO_SET_POLL_FLAGS, NULL, nwal_POLL_DEFAULT_GLOB_PKT_Q};
179 //template for fast path
180 nwalTxPktInfo_t txPktInfoNoCrypto =
181 {
182 NULL, /* p_pkt */
183 NWAL_TX_FLAG1_META_DATA_VALID, /* txFlags */
184 0, /* lpbackPass */
185 0, /* enetport */
186 0, /* msuSize */
187 0, /* startOffset */
188 0, /* saOffBytes */
189 0, /* saPayLoadLen */
190 0 , /* saAhIcvOffBytes */
191 0, /* saAhMacSize */
192 0,
193 /* etherLenOffBytes */
194 netTest_MAC_HEADER_LEN, /* ipOffBytes */
195 netTest_MAC_HEADER_LEN +netTest_IP_HEADER_LEN, /* l4OffBytes */
196 netTest_UDP_HEADER_LEN, /* l4HdrLen */
197 0, /* pseudoHdrChecksum */
198 0 /* pLoadLen */
199 };
202 NETCP_CFG_ROUTE_T test_route=
203 {
204 0,
205 NULL,
206 NULL,
207 0//* to be filled in
208 };
211 /*************************END NETAPI OBJECTS***********************/
213 static unsigned char all_mac[]={0,0,0,0,0,0};
215 static unsigned long last_header[32/sizeof(unsigned long)];
218 //stats
219 int pkt_rx=0;
220 int pkt_tx=0;
221 unsigned long long pkt_rx_cycles=0L;
222 unsigned long long pkt_tx_cycles=0L;
223 unsigned long long pkt_cb_cycles=0L;
224 unsigned long long idle_cycles=0L;
225 volatile unsigned long long start_time;
226 unsigned long long end_time;
228 //**********************************
229 //producer thread
230 //*********************************
231 void producer_thread(int coreid)
232 {
233 int err;
234 int i;
235 Ti_Pkt * tip;
236 unsigned char * pData;
237 int len;
238 PKTIO_METADATA_T meta = {PKTIO_META_IFDMA_TX,{0},0};
239 int np;
240 cpu_set_t cpu_set;
241 unsigned long t1;
242 unsigned long t2;
244 CPU_ZERO( &cpu_set);
245 CPU_SET( 2, &cpu_set);
246 hplib_utilSetupThread(2, &cpu_set, hplib_spinLock_Type_LOL);
247 start_time = hplib_mUtilGetTimestamp();
249 //DAL we poll the default pktio channel for pkts from net
250 for(i=0;!((volatile) QUIT);i++)
251 {
252 t1 = netapi_timing_start();
253 np = netapi_pktioPoll(netcp_rx_chan,NULL,&err);
254 t2 = netapi_timing_start();
255 pkt_rx+=np;
256 if (np)
257 {
258 pkt_rx_cycles += (t2-t1);
259 }
260 else
261 {
262 idle_cycles += (t2-t1);
263 }
264 if (RESET)
265 {
266 idle_cycles=0LL;
267 start_time = hplib_mUtilGetTimestamp();
268 pkt_rx=pkt_tx=0;
269 pkt_rx_cycles=pkt_tx_cycles=0LL;
270 pkt_cb_cycles=0LL;
271 RESET=0;
272 }
273 }
274 end_time = hplib_mUtilGetTimestamp();
275 printf("nt-bench: receiver DONE %d pkts rx, pkt poll cycles=% u; pkt rx cycle=%u pkt tx cycles=%u idle cycles=%lld duration=%lld ticks idle pct= %lld\n",
276 pkt_rx,
277 (unsigned) (pkt_rx ? (pkt_rx_cycles - pkt_cb_cycles)/pkt_rx : 0),
278 (unsigned) (pkt_rx ? (pkt_rx_cycles) /pkt_rx : 0),
279 (unsigned) (pkt_tx ? (pkt_tx_cycles) /pkt_tx : 0),
280 idle_cycles, (end_time-start_time),
281 (idle_cycles*100) /( CALIB* (end_time-start_time))
283 );
284 printf("Leaving producer_thread\n");
285 }
288 //******************************
289 // main program
290 //*****************************
291 int main(int argc, char **argv)
292 {
293 int err,i;
294 int32_t errCode;
295 Pktlib_HeapIfTable* pPktifTable;
296 Pktlib_HeapCfg heapCfg;
297 long t1, t2 ;
298 cpu_set_t cpu_set;
301 //install signal handler for ^c
302 signal(SIGINT,netTest_utilMySig);
309 CPU_ZERO( &cpu_set);
310 CPU_SET( 0, &cpu_set);
311 hplib_utilSetupThread(2, &cpu_set, hplib_spinLock_Type_LOL);
314 /*******************************************/
315 /*************NETAPI STARTUP****************/
316 /*******************************************/
318 /* create netapi */
319 netapi_handle = netapi_init(NETAPI_SYS_MASTER,
320 &our_netapi_default_cfg);
321 if (netapi_handle == NULL)
322 {
323 printf("main: netapi_init failure, exiting\n");
324 exit(1);
325 }
326 netapi_netcpCfgExceptions(netapi_handle, NETCP_CFG_ALL_EXCEPTIONS, NETCP_CFG_ACTION_DISCARD, (NETCP_CFG_ROUTE_HANDLE_T) NULL);
328 /* open the main heap */
329 OurHeap = Pktlib_findHeapByName("netapi");
330 if (!OurHeap) {printf("findheapbyname fail\n"); exit(1);}
332 //if we want to relay network packets, we create a handle to the
333 //default netcp receive queue here
334 netcp_rx_chan= netapi_pktioOpen(netapi_handle, NETCP_RX, (PKTIO_CB) recv_cb_net, &netcp_rx_cfg, &err);
335 if (!netcp_rx_chan) {printf("pktio open RX failed err=%d\n",err); exit(1);}
337 netcp_tx_chan= netapi_pktioOpen(netapi_handle, NETCP_TX, (PKTIO_CB) NULL, &netcp_tx_cfg, &err);
338 if (!netcp_tx_chan) {printf("pktio open TX failed err=%d\n",err); exit(1);}
339 else //install a fast path template into the NETCP TX channel
340 {
341 PKTIO_CONTROL_T control2;
342 control2.op = PKTIO_UPDATE_FAST_PATH;
343 PKTIO_CFG_T cfg2;
344 cfg2.fast_path_cfg.fp_send_option = PKTIO_FP_NO_CRYPTO_NO_CKSUM_PORT;
345 cfg2.fast_path_cfg.txPktInfo= &txPktInfoNoCrypto;
346 netapi_pktioControl(netcp_tx_chan, NULL, &cfg2, &control2, &err);
347 }
350 /*********************************************/
351 /*****************end NETAPI STARTUP**********/
352 /*********************************************/
354 /*************************************************
355 ********************some basic benchmarks*********
356 **************************************************/
357 printf("\n\n*******STARTING MEM ACCESS BENCHMARK*********\n\n");
358 benchmarks1();
359 printf("\n\n*******STARTING RAW BENCHMARK2*********\n\n");
360 benchmarks2(OurHeap, 20);
361 printf("\n\n*******STARTING RAW BENCHMARK3*********\n\n");
362 benchmarks3(OurHeap, 20);
363 printf("\n\n******STARTING RECV BENCHMARK (q to quit)*****\n\n");
366 //now creaate a simple netcp rule
367 //to get a lot of packets
368 netapi_netcpCfgCreateMacInterface(
369 netapi_handle,
370 &all_mac[0],
371 NULL,
372 0,0,
373 (NETCP_CFG_ROUTE_HANDLE_T) NULL,
374 (NETCP_CFG_VLAN_T ) NULL , //future
375 1,
376 &err);
378 //calibrate idle
379 CALIB = calibrate_idle();
381 //**************************************
382 //Create a worked thread
383 //***************************************
384 {
385 pthread_t *thrs;
386 int procs =1;
387 char c;
388 thrs = malloc( sizeof( pthread_t ) * procs );
389 if (thrs == NULL)
390 {
391 perror( "malloc" );
392 return -1;
393 }
394 printf( "benchmark-test: Starting %d threads...\n", procs );
396 if (pthread_create( &thrs[0], NULL, (void*)producer_thread,
397 (void *)0 ))
398 {
399 perror( "pthread_create" );
400 exit(1);
401 }
402 //this thread of execution (main) now just waits on user input
403 for(;;)
404 {
405 printf(">");
406 c=getchar();
407 if (c=='c') {CAP=!CAP; printf("CAPTURE= %d\n", CAP); }
408 else if (c=='q') {QUIT=1;break;}
409 else if (c=='t') {XMIT=!XMIT; printf("XMIT= %d\n", XMIT); }
410 else if (c=='s')
411 {
412 unsigned long long et= hplib_mUtilGetTimestamp();
413 printf(">NT_BENCH STATS: %d received %d xmitted, %lld idle cycles, %lld duration ticks idle=%lld\n",
414 pkt_rx,pkt_tx,
415 idle_cycles,
416 (et-start_time),
417 (idle_cycles*100)/(CALIB*(et-start_time))
418 );
419 }
420 else if (c=='r')
421 {
422 RESET=1;
423 }
424 else if (c=='h')
425 {
426 printf("> 'q' to quit, 's' for stats, 't' to toggle transmit 'c' to toggle capture, 'd' to dump capture, 'r' to reset idle counters, 'h' for help\n");
427 }
428 else if (c=='d')
429 {
430 netTest_utilDumpHeader(&last_header[0], 0,0,0);
431 }
432 }
434 //wait for completion
435 printf("main task now pending on thread completion\n");
436 for (i = 0; i < procs; i++)
437 pthread_join( thrs[i], NULL );
439 free( thrs );
441 }
443 /*************************************************
444 ************CLEAN UP****************************
445 ************************************************/
446 //get rid of rule, in the case that we are relaying packets
447 //also close our netcp rx channel
448 netapi_netcpCfgDelMac(netapi_handle,0,&err);
449 netapi_pktioClose(netcp_rx_chan,&err);
450 netapi_pktioClose(netcp_tx_chan,&err);
453 //done
454 netapi_shutdown(netapi_handle);
457 //!finished!
458 }
459 static inline void sendit(Ti_Pkt *tip, int len, int out_port)
460 {
461 int err=0;
462 PKTIO_METADATA_T meta2 = {PKTIO_META_TX,{0},0};
463 nwalTxPktInfo_t meta_tx2={0};
464 if (len<60)
465 {
466 unsigned int templen;
467 char * p_pkt;
468 len=60;
469 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
470 Cppi_setData (Cppi_DescType_HOST, (Cppi_Desc *) tip, p_pkt,len);
471 }
472 Pktlib_setPacketLen(tip,len);
473 meta_tx2.txFlag1 = NWAL_TX_FLAG1_META_DATA_VALID ;
474 meta_tx2.ploadLen = len ;
475 meta_tx2.enetPort=out_port;
476 meta2.u.tx_meta=&meta_tx2;
477 netapi_pktioSend(netcp_tx_chan,tip,&meta2,&err);
478 }
480 //receive callback for packets from net (for consumer)
481 void recv_cb_net(struct PKTIO_HANDLE_Tag * channel, Ti_Pkt* p_recv[],
482 PKTIO_METADATA_T meta[], int n_pkts,
483 uint64_t ts )
484 {
485 int i;
486 Ti_Pkt * tip;
487 int len;
488 unsigned long t1;
489 unsigned long t2;
490 unsigned long t3;
491 unsigned long t4;
492 pasahoLongInfo_t* protoInfo;
493 int ifno;
494 int out_port;
496 t1= netapi_timing_start();
497 for(i=0;i<n_pkts;i++)
498 {
499 tip = p_recv[i];
500 len = Pktlib_getPacketLen(tip);
502 if (CAP)
503 {
504 unsigned int templen;
505 char * p_pkt;
506 Pktlib_getDataBuffer(tip,(uint8_t**)&p_pkt,&templen);//ignore templen
507 memcpy(last_header,p_pkt,32);
508 }
510 if (XMIT)
511 {
512 protoInfo=nwal_mGetProtoInfo(tip);
513 ifno = nwal_mGetRxEmacPort( protoInfo);
514 //----------------------------------------------------
515 //very trivial bridging -> just output to other port!
516 //----------------------------------------------------
517 if (ifno ==1) out_port=2; else out_port=1;
518 t3= netapi_timing_start();
519 sendit(tip,len,out_port);
520 pkt_tx+=1;
521 t4= netapi_timing_start();
522 pkt_tx_cycles += (t4-t3);
523 }
524 else
525 {
526 Pktlib_freePacket((Ti_Pkt*)tip);
527 }
528 }
529 t2 = netapi_timing_start();
530 pkt_cb_cycles += (t2-t1);
531 }
536 //SOME BENCHMARKS
537 //sonme benchmarks
538 void benchmarks1(void)
539 {
540 int i,j;
541 unsigned long v1pop;
542 unsigned long v2pop;
543 unsigned long v1push;
544 unsigned long v2push;
545 unsigned long v1read;
546 unsigned long v2read;
547 unsigned long v1write;
548 unsigned long v2write;
549 unsigned long v1read2;
550 unsigned long v2read2;
551 #define N 100
552 Ti_Pkt pkts[N];
553 unsigned char * p_pkt;
554 int len;
555 int sum=0;
556 int sum2=0;
557 char *p=(char *) malloc(1000);
558 //alloc
559 v1pop=netapi_timing_start();
560 for(i=0;i<N;i++) pkts[i]= Pktlib_allocPacket(OurHeap,1000);
561 v2pop = netapi_timing_start();
563 //write access
564 Pktlib_getDataBuffer(pkts[0],(uint8_t**)&p_pkt,&len);
565 v1write=netapi_timing_start();
566 for(i=0;i<1000;i++) p_pkt[i]=i;
567 v2write=netapi_timing_start();
569 //read access
570 v1read=netapi_timing_start();
571 for(j=0;j<10;j++)
572 for(i=0;i<1000;i++) sum+=p_pkt[i];
573 v2read=netapi_timing_start();
575 // access (from malloc)
576 v1read2=netapi_timing_start();
577 for(i=0;i<1000;i++) sum2+=p[i];
578 v2read2=netapi_timing_start();
580 //free packet
581 v1push=netapi_timing_start();
582 for(i=0;i<N;i++) Pktlib_freePacket(pkts[i]);
583 v2push = netapi_timing_start();
585 //resutls
586 printf("allocs= %d free=%d write=%d read=%d read-malloc=%d (sum=%d %d)\n",
587 (v2pop-v1pop)/N, (v2push-v1push)/N, (v2write-v1write)/1000, (v2read-v1read)/10000,
588 (v2read2-v1read2)/1000,sum,sum2);
591 };
594 //raw queue benchmark
595 #include "ti/drv/nwal/nwal_util.h"
597 #define NTOPOP 150
598 volatile unsigned long t1;
599 volatile unsigned long t2;
600 volatile unsigned long t3;
601 volatile unsigned long t4;
602 volatile unsigned long t5;
603 volatile unsigned long t6;
604 volatile unsigned long sum1=0;
605 volatile unsigned long sum2=0;
606 volatile unsigned long sum3=0;
607 volatile unsigned long sum4=0;
608 volatile Ti_Pkt * pHd[NTOPOP];
610 void * pop_raw(int n)
611 {
613 }
614 void * p2v (void* in)
615 {
618 }
619 void * v2p(void * in)
620 {
622 }
623 void push_raw(void *pkt, int n)
624 {
626 }
628 void benchmarks2(Pktlib_HeapHandle h , int ntrials)
629 {
630 int i,j;
631 int k;
632 int abort=0;
633 Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
635 //n_trials of NTOPOP actions
636 for(i=0;i<ntrials;i++)
637 {
638 abort=0;
639 sum1=sum2=sum3=sum4=0;
640 //raw pop
641 t1= netapi_timing_start();
642 for(j=0;j<NTOPOP;j++)
643 {
644 pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(pktio_mQmssQueuePopRaw (freeQ));
645 if (!pHd[j])
646 {
647 printf("abort test. out of descriptors\n"); abort=1;
648 break;
649 }
650 }
651 t2= netapi_timing_start();
652 k=j;
653 for(j=0;j<k;j++)
654 {
655 pHd[j] = Osal_qmssConvertDescPhyToVirt(0,pHd[j]);
656 }
657 t3= netapi_timing_start();
658 sum1 += (t2-t1);
659 sum2 += (t3-t2);
660 //raw push
661 t4= netapi_timing_start();
662 for(j=0;j<k;j++)
663 {
664 if (!pHd[j]) continue;
665 pHd[j]= Osal_qmssConvertDescVirtToPhy(0,pHd[j]);
666 }
667 t5= netapi_timing_start();
668 for(j=0;j<k;j++)
669 {
670 pktio_mQmssQueuePushDescSizeRaw(freeQ,
671 (void *) pHd[j],
672 128);
673 }
674 t6= netapi_timing_start();
675 sum3 += (t5-t4);
676 sum4 += (t6-t5);
678 if (!abort)
679 printf("nt=%d raw pop=%d p2v=%d v2p=%d raw push=%d\n", i,
680 sum1/k, sum2/k, sum3/k, sum4/k);
681 sleep(1);
682 }
683 return;
684 }
686 //full queue push/pops
687 void benchmarks3(Pktlib_HeapHandle h , int ntrials)
688 {
689 int i,j;
690 int k;
691 int abort=0;
692 Qmss_QueueHnd freeQ=Pktlib_getInternalHeapQueue(h);
694 //n_trials of NTOPOP actions
695 for(i=0;i<ntrials;i++)
696 {
697 abort=0;
698 sum2=sum4=0;
699 //raw pop
700 t1= netapi_timing_start();
701 for(j=0;j<NTOPOP;j++)
702 {
703 pHd[j] = (Ti_Pkt *)QMSS_DESC_PTR(Qmss_queuePop(freeQ));
704 if (!pHd[j])
705 {
706 printf("abort test. out of descriptors\n"); abort=1;
707 break;
708 }
709 }
710 t3= netapi_timing_start();
711 sum2 += (t3-t1);
712 k=j;
713 //raw push
714 t5= netapi_timing_start();
715 for(j=0;j<k;j++)
716 {
717 if (!pHd[j]) continue;
718 Qmss_queuePushDescSize(freeQ, pHd[j], 128);
719 }
720 t6= netapi_timing_start();
721 sum4 += (t6-t5);
722 if (!abort)
723 printf("nt=%d pop=%d push=%d\n", i,
724 sum2/k, sum4/k);
725 sleep(1);
726 }
727 return;
728 }