00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <assert.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include "kapi_internal.h"
00032 #include "kapi_error.h"
00033
00034
00035
00036
00037 int
00038 KAPI_CoreLatency( void *pConfig, kapi_fu_t fuProd, int opp )
00039 {
00040 knobs_t *pknobs = pConfig;
00041
00042 assert( pknobs->dmpfuinfoTable[ fuProd ].iCoreLatency[ opp ] >= 0 );
00043 return( pknobs->dmpfuinfoTable[ fuProd ].iCoreLatency[ opp ] );
00044 }
00045
00046 int
00047 KAPI_InterClusterBypass( void *pConfig,
00048 kapi_cluster_t clusterProd, kapi_fu_t fuProd,
00049 int oppProd, kapi_ut_t utProd, kapi_cutport_t cutportProd,
00050 kapi_cluster_t clusterCons, kapi_fu_t fuCons,
00051 int oppCons, kapi_ut_t utCons, kapi_cutport_t cutportCons )
00052 {
00053 knobs_t *pknobs = pConfig;
00054 int i;
00055
00056
00057 for ( i=0;i<pknobs->nRawInter;i++ ) {
00058 eby_t *peby;
00059
00060 peby = &(pknobs->dmpebyInterTable[ i ]);
00061
00062 if ( ( clusterProd != peby->clusterSrc && peby->clusterSrc != -1 ) ||
00063 ( clusterCons != peby->clusterDest && peby->clusterDest != -1 ) ) {
00064 continue;
00065 }
00066
00067 if ( fuProd != peby->fuSrc ||
00068 fuCons != peby->fuDest ) {
00069 continue;
00070 }
00071
00072 if ( oppProd != peby->oppSrc ||
00073 oppCons != peby->oppDest ) {
00074 continue;
00075 }
00076
00077 if ( ( cutportProd != peby->cutportSrc && peby->cutportSrc != -1 ) ||
00078 ( cutportCons != peby->cutportDest && peby->cutportDest != -1 ) ) {
00079 continue;
00080 }
00081
00082 return( peby->iValue );
00083 }
00084
00085
00086 return( 0 );
00087 }
00088
00089 int
00090 KAPI_IntraClusterBypass( void *pConfig,
00091 kapi_cluster_t cluster,
00092 kapi_fu_t fuProd, int oppProd, kapi_ut_t utProd, kapi_cutport_t
00093 cutportProd,
00094 kapi_fu_t fuCons, int oppCons, kapi_ut_t utCons, kapi_cutport_t
00095 cutportCons )
00096 {
00097 knobs_t *pknobs = pConfig;
00098 int i;
00099
00100
00101 for ( i=0;i<pknobs->nRawIntra;i++ ) {
00102 aby_t *paby;
00103
00104
00105 paby = &(pknobs->dmpabyIntraTable[ i ]);
00106
00107 if ( ( cluster != paby->cluster && paby->cluster != -1 ) ) {
00108 continue;
00109 }
00110
00111 if ( fuProd != paby->fuSrc ||
00112 fuCons != paby->fuDest ) {
00113 continue;
00114 }
00115
00116 if ( oppProd != paby->oppSrc ||
00117 oppCons != paby->oppDest ) {
00118 continue;
00119 }
00120
00121 if ( ( utProd != paby->utSrc && paby->utSrc != -1 ) ||
00122 ( utCons != paby->utDest && paby->utDest != -1 ) ) {
00123 continue;
00124 }
00125
00126 if ( ( cutportProd != paby->cutportSrc && paby->cutportSrc != -1 ) ||
00127 ( cutportCons != paby->cutportDest && paby->cutportDest != -1 ) ) {
00128 continue;
00129 }
00130
00131 #if 0
00132 printf( "Found: %d %d %d %d --> %d %d %d %d = %d\n",
00133 fuProd, oppProd, utProd, cutportProd,
00134 fuCons, oppCons, utCons, cutportCons, paby->iValue);
00135 #endif
00136
00137 return( paby->iValue );
00138 }
00139
00140
00141 #if 0
00142 printf( "NOT Found: %d %d %d %d --> %d %d %d %d = %d\n",
00143 fuProd, oppProd, utProd, cutportProd,
00144 fuCons, oppCons, utCons, cutportCons, 0);
00145 #endif
00146 return( 0 );
00147 }
00148
00149 int
00150 KAPI_ClusterDistance( void *pConfig,
00151 kapi_cluster_t clusterProd, kapi_cluster_t clusterCons )
00152 {
00153 knobs_t *pknobs = pConfig;
00154
00155 return( pknobs->mpclrTable[ clusterProd ].distClr[ clusterCons ] );
00156 }
00157
00158 int
00159 KAPI_TotalLatency( void *pConfig,
00160 kapi_cluster_t clusterProd, kapi_fu_t fuProd,
00161 int oppProd, kapi_ut_t utProd, kapi_cutport_t cutportProd,
00162 kapi_cluster_t clusterCons, kapi_fu_t fuCons,
00163 int oppCons, kapi_ut_t utCons, kapi_cutport_t cutportCons )
00164 {
00165 int result;
00166
00167 if ( clusterProd != clusterCons ) {
00168
00169 result = KAPI_InterClusterBypass( pConfig,
00170 clusterProd, fuProd, oppProd, utProd,
00171 cutportProd,
00172 clusterCons, fuCons, oppCons, utCons,
00173 cutportCons )
00174 + KAPI_CoreLatency( pConfig, fuProd, oppProd )
00175 + KAPI_ClusterDistance( pConfig, clusterProd, clusterCons );
00176 } else {
00177
00178 result = KAPI_IntraClusterBypass( pConfig, clusterProd, fuProd, oppProd,
00179 utProd, cutportProd,
00180 fuCons, oppCons, utCons, cutportCons
00181 )
00182 + KAPI_CoreLatency( pConfig, fuProd, oppProd );
00183 }
00184 return( result );
00185 }
00186
00187
00188 papair_t *mppapairList = NULL;
00189 pepair_t *mppepairList = NULL;
00190
00191
00192 papair_t *
00193 KAPI_IntraClusterBypassList( void *pConfig, kapi_cluster_t cluster,
00194 kapi_fu_t fuSrc, int oppSrc, kapi_ut_t utSrc,
00195 kapi_cutport_t cutportSrc,
00196 kapi_fu_t fuDest, int oppDest, kapi_ut_t utDest,
00197 kapi_cutport_t cutportDest,
00198 int *pnbypass )
00199 {
00200 knobs_t *pknobs = pConfig;
00201 aby_t *paby;
00202 int cnt, iaby;
00203 cnt = 0;
00204
00205
00206 if (mppapairList == NULL)
00207 {
00208 mppapairList = (papair_t *)calloc(pknobs->nRawIntra, sizeof (papair_t));
00209 if (mppapairList == NULL)
00210 {
00211 fprintf(stderr, "Allocate copy of intra bypass list failed!\n");
00212 return NULL;
00213 }
00214 }
00215
00216 for ( iaby=0; iaby<pknobs->nRawIntra; iaby++ ) {
00217 paby = &(pknobs->dmpabyIntraTable[ iaby ]);
00218
00219 if ( !( cluster == paby->cluster
00220 || cluster == -1 || paby->cluster == -1 ) ) {
00221 continue;
00222 }
00223
00224
00225 if ( !( fuSrc == paby->fuSrc || fuSrc == -1 ) ) {
00226 continue;
00227 }
00228
00229 if ( !( fuDest == paby->fuDest || fuDest == -1 ) ) {
00230 continue;
00231 }
00232
00233
00234
00235 if ( !( oppSrc == paby->oppSrc || oppSrc == -1 ) ) {
00236 continue;
00237 }
00238
00239 if ( !( oppDest == paby->oppDest || oppDest == -1 ) ) {
00240 continue;
00241 }
00242
00243
00244
00245 if ( !( cutportSrc == paby->cutportSrc
00246 || cutportSrc == -1 || paby->cutportSrc == -1 ) ) {
00247 continue;
00248 }
00249
00250 if ( !( cutportDest == paby->cutportDest
00251 || cutportDest == -1 || paby->cutportDest == -1 ) ) {
00252 continue;
00253 }
00254
00255
00256
00257 if ( !( utSrc == paby->utSrc
00258 || utSrc == -1 || paby->utSrc == -1 ) ) {
00259 continue;
00260 }
00261
00262 if ( !( utDest == paby->utDest
00263 || utDest == -1 || paby->utDest == -1 ) ) {
00264 continue;
00265 }
00266
00267 mppapairList[ cnt ].cluster = paby->cluster;
00268 mppapairList[ cnt ].cutportSrc = paby->cutportSrc;
00269 mppapairList[ cnt ].cutportDest = paby->cutportDest;
00270 mppapairList[ cnt ].utSrc = paby->utSrc;
00271 mppapairList[ cnt ].utDest = paby->utDest;
00272 mppapairList[ cnt ].fuSrc = paby->fuSrc;
00273 mppapairList[ cnt ].fuDest = paby->fuDest;
00274 mppapairList[ cnt ].oppSrc = paby->oppSrc;
00275 mppapairList[ cnt ].oppDest = paby->oppDest;
00276 mppapairList[ cnt ].iValue = paby->iValue;
00277
00278 cnt++;
00279 }
00280
00281 *pnbypass = cnt;
00282 return( &(mppapairList[ 0 ]) );
00283 }
00284
00285
00286 pepair_t *
00287 KAPI_InterClusterBypassList( void *pConfig,
00288 kapi_cluster_t clusterSrc,
00289 kapi_fu_t fuSrc, int oppSrc, kapi_ut_t utSrc,
00290 kapi_cutport_t cutportSrc,
00291 kapi_cluster_t clusterDest,
00292 kapi_fu_t fuDest, int oppDest, kapi_ut_t utDest,
00293 kapi_cutport_t cutportDest,
00294 int *pnbypass)
00295 {
00296 knobs_t *pknobs = pConfig;
00297 eby_t *peby;
00298 int cnt, ieby;
00299
00300
00301 cnt = 0;
00302
00303
00304 if (mppepairList == NULL)
00305 {
00306 mppepairList = (pepair_t *)calloc(pknobs->nRawIntra, sizeof (pepair_t));
00307 if (mppepairList == NULL)
00308 {
00309 fprintf(stderr, "Allocate copy of inter bypass list failed!\n");
00310 return NULL;
00311 }
00312 }
00313
00314
00315 for ( ieby=0; ieby<pknobs->nRawInter; ieby++ ) {
00316 peby = &(pknobs->dmpebyInterTable[ ieby ]);
00317
00318
00319 if ( !( clusterSrc == peby->clusterSrc
00320 || clusterSrc == -1 ) ) {
00321 continue;
00322 }
00323
00324 if ( !( clusterDest == peby->clusterDest
00325 || clusterDest == -1 ) ) {
00326 continue;
00327 }
00328
00329
00330 if ( !( fuSrc == peby->fuSrc || fuSrc == -1 ) ) {
00331 continue;
00332 }
00333
00334 if ( !( fuDest == peby->fuDest || fuDest == -1 ) ) {
00335 continue;
00336 }
00337
00338
00339
00340 if ( !( oppSrc == peby->oppSrc || oppSrc == -1 ) ) {
00341 continue;
00342 }
00343
00344 if ( !( oppDest == peby->oppDest || oppDest == -1 ) ) {
00345 continue;
00346 }
00347
00348
00349
00350 if ( !( cutportSrc == peby->cutportSrc
00351 || cutportSrc == -1
00352 || peby->cutportSrc == -1 ) ) {
00353 continue;
00354 }
00355
00356 if ( !( cutportDest == peby->cutportDest
00357 || cutportDest == -1
00358 || peby->cutportDest == -1 ) ) {
00359 continue;
00360 }
00361
00362
00363
00364 if ( !( utSrc == peby->utSrc
00365 || utSrc == -1
00366 || peby->utSrc == -1 ) ) {
00367 continue;
00368 }
00369
00370 if ( !( utDest == peby->utDest
00371 || utDest == -1
00372 || peby->utDest == -1 ) ) {
00373 continue;
00374 }
00375
00376 mppepairList[ cnt ].clusterSrc = peby->clusterSrc;
00377 mppepairList[ cnt ].clusterDest = peby->clusterDest;
00378 mppepairList[ cnt ].cutportSrc = peby->cutportSrc;
00379 mppepairList[ cnt ].cutportDest = peby->cutportDest;
00380 mppepairList[ cnt ].utSrc = peby->utSrc;
00381 mppepairList[ cnt ].utDest = peby->utDest;
00382 mppepairList[ cnt ].fuSrc = peby->fuSrc;
00383 mppepairList[ cnt ].fuDest = peby->fuDest;
00384 mppepairList[ cnt ].oppSrc = peby->oppSrc;
00385 mppepairList[ cnt ].oppDest = peby->cutportDest;
00386 mppepairList[ cnt ].iValue = peby->utSrc;
00387
00388 cnt++;
00389 }
00390
00391 *pnbypass = cnt;
00392 return( &(mppepairList[ 0 ]) );
00393 }
00394
00395 int
00396 KAPI_MinIntraClusterTotalLatency( void *pConfig, kapi_cluster_t cluster,
00397 kapi_fu_t fuProd, int oppProd, kapi_fu_t fuCons, int oppCons )
00398 {
00399 knobs_t *pknobs = pConfig;
00400 int latcore, minlatbypass, latbypass;
00401 kapi_ut_t utSrc, utDest;
00402 int oppProdTmp,oppConsTmp,oppProdStart,oppProdEnd,oppConsStart,oppConsEnd;
00403
00404 #if 0
00405 papair_t *ppapair, *ppapairList;
00406 int nbypass;
00407 ppapairList = KAPI_IntraClusterBypassList( pConfig, cluster,
00408 fuProd, oppProd, -1, -1,
00409 fuCons, oppCons, -1, -1,
00410 &nbypass );
00411 #endif
00412
00413 minlatbypass = 10000;
00414
00415 if (oppProd==-1)
00416 {
00417 oppProdStart=0;
00418 oppProdEnd=pknobs->dmpfuinfoTable[ fuProd ].cntDest;
00419 } else
00420 {
00421 oppProdStart=oppProd;
00422 oppProdEnd=oppProdStart+1;
00423 }
00424
00425 if (oppCons==-1)
00426 {
00427 oppConsStart=0;
00428 oppConsEnd=pknobs->dmpfuinfoTable[ fuCons ].cntSrc;
00429 } else
00430 {
00431 oppConsStart=oppCons;
00432 oppConsEnd=oppConsStart+1;
00433 }
00434 for (oppProdTmp=oppProdStart;oppProdTmp<oppProdEnd;oppProdTmp++)
00435 {
00436 for (oppConsTmp=oppConsStart;oppConsTmp<oppConsEnd;oppConsTmp++)
00437 {
00438 for ( utSrc=0; utSrc< kapi_nUT; utSrc++ ) {
00439 for ( utDest=0; utDest< kapi_nUT; utDest++ ) {
00440
00441 latbypass = KAPI_IntraClusterBypass( pConfig,
00442 cluster,
00443 fuProd, oppProdTmp, utSrc, 0,
00444 fuCons, oppConsTmp, utDest, 0 );
00445
00446 if ( latbypass < minlatbypass ) {
00447 minlatbypass = latbypass;
00448 }
00449 }
00450 }
00451 }
00452 }
00453
00454 latcore = KAPI_CoreLatency( pConfig, fuProd, oppProd );
00455
00456 assert( minlatbypass != 10000 );
00457 return( latcore + minlatbypass );
00458 }
00459
00460
00461 int
00462 KAPI_MaxIntraClusterTotalLatency( void *pConfig, kapi_cluster_t cluster,
00463 kapi_fu_t fuProd, int oppProd, kapi_fu_t fuCons, int oppCons )
00464 {
00465 knobs_t *pknobs = pConfig;
00466 int latcore, maxnlatbypass, latbypass;
00467 kapi_ut_t utSrc, utTar;
00468 int oppProdTmp,oppConsTmp,oppProdStart,oppProdEnd,oppConsStart,oppConsEnd;
00469
00470 maxnlatbypass = -1;
00471
00472 if (oppProd==-1)
00473 {
00474 oppProdStart=0;
00475 oppProdEnd=pknobs->dmpfuinfoTable[ fuProd ].cntDest;
00476 } else
00477 {
00478 oppProdStart=oppProd;
00479 oppProdEnd=oppProdStart+1;
00480 }
00481
00482 if (oppCons==-1)
00483 {
00484 oppConsStart=0;
00485 oppConsEnd=pknobs->dmpfuinfoTable[ fuCons ].cntSrc;
00486 } else
00487 {
00488 oppConsStart=oppCons;
00489 oppConsEnd=oppConsStart+1;
00490 }
00491 for (oppProdTmp=oppProdStart;oppProdTmp<oppProdEnd;oppProdTmp++)
00492 {
00493 for (oppConsTmp=oppConsStart;oppConsTmp<oppConsEnd;oppConsTmp++)
00494 {
00495 for ( utSrc=0; utSrc< kapi_nUT; utSrc++ ) {
00496 for ( utTar=0; utTar< kapi_nUT; utTar++ ) {
00497
00498 latbypass = KAPI_IntraClusterBypass( pConfig,
00499 cluster,
00500 fuProd, oppProdTmp, utSrc, 0,
00501 fuCons, oppConsTmp, utTar, 0 );
00502
00503 if ( latbypass > maxnlatbypass ) {
00504 maxnlatbypass = latbypass;
00505 }
00506 }
00507 }
00508 }
00509 }
00510
00511 latcore = KAPI_CoreLatency( pConfig, fuProd, oppProd );
00512
00513 assert( maxnlatbypass != -1 );
00514 return( latcore + maxnlatbypass );
00515 }
00516
00517