77static pdbg_progress_tick_t progress_tick ;
88static bool pdbg_short_context = false;
99
10+ #define MAX_PEER_TYPE_ENTRIES 3
11+
12+ typedef struct {
13+ char key [120 ];
14+ char value [120 ];
15+ } peer_map_struct ;
16+
17+ peer_map_struct peer_map [MAX_PEER_TYPE_ENTRIES ] = {
18+ {"tbusl" , "tbusl" },
19+ {"core" , "l3cache" },
20+ {"l3cache" , "core" },
21+ };
22+
1023struct pdbg_target * get_parent (struct pdbg_target * target , bool system )
1124{
1225 struct pdbg_target * parent ;
@@ -372,33 +385,61 @@ char* extract_string_after_colon(char* input)
372385 return "" ;
373386}
374387
388+
389+ // Function to get peer class name
390+ const char * get_peer_class_name (const char * key ) {
391+
392+ for (int i = 0 ; i < MAX_PEER_TYPE_ENTRIES ; i ++ ) {
393+ if (strcmp (peer_map [i ].key , key ) == 0 ) {
394+ return peer_map [i ].value ;
395+ }
396+ }
397+ return NULL ; // Key not found
398+ }
399+
400+ struct pdbg_target * pdbg_get_pnode (struct pdbg_target * target )
401+ {
402+ return target -> pnode ;
403+ }
404+
375405struct pdbg_target * pdbg_get_peer_target (struct pdbg_target * target )
376406{
377- char tgtPeerPath [120 ];
378- if (!pdbg_target_get_attribute (target , "ATTR_PEER_PATH" , 1 , 120 ,
379- tgtPeerPath )) {
380- //unable to find the path
381- pdbg_log (PDBG_ERROR , "unable to find the attribute ATTR_PEER_PATH for %s\n" ,
382- pdbg_target_path (target ));
383- }
384- else
407+ //Get the class type to find its appropriate peer
408+ const char * peer_class_name = get_peer_class_name (target -> class );
409+
410+ //As get attr is an expensive operation, check if the current class
411+ //is expected to have a peer class
412+ if (peer_class_name )
385413 {
386- struct pdbg_target * same_class_target ;
387- //The peer could only be of the same type, so look for all the targets of that type
388- pdbg_for_each_class_target (target -> class , same_class_target )
414+ char tgtPeerPath [120 ];
415+ if (!pdbg_target_get_attribute (target , "ATTR_PEER_PATH" , 1 , 120 ,
416+ tgtPeerPath )) {
417+ //unable to find the path
418+ pdbg_log (PDBG_ERROR , "unable to find the attribute ATTR_PEER_PATH for %s\n" ,
419+ pdbg_target_path (target ));
420+ }
421+ else
389422 {
390- char tgtPhyPath [120 ];
391- if (pdbg_target_get_attribute (same_class_target , "ATTR_PHYS_DEV_PATH" , 1 , 120 ,
392- tgtPhyPath )) {
393- //unable to find the path
394- if ( strcmp (extract_string_after_colon (tgtPhyPath ), extract_string_after_colon (tgtPeerPath )) == 0 )
395- {
396- return same_class_target ;
423+ struct pdbg_target * traversed_target ;
424+ //The peer could only be of the same type, so look for all the targets of that type
425+ pdbg_for_each_class_target (peer_class_name , traversed_target )
426+ {
427+ char tgtPhyPath [120 ];
428+ if (pdbg_target_get_attribute (traversed_target , "ATTR_PHYS_DEV_PATH" , 1 , 120 ,
429+ tgtPhyPath )) {
430+ //unable to find the path
431+ if ( strcmp (extract_string_after_colon (tgtPhyPath ), extract_string_after_colon (tgtPeerPath )) == 0 )
432+ {
433+ return traversed_target ;
434+ }
397435 }
398436 }
437+
399438 }
439+ pdbg_log (PDBG_ERROR , "unable to find the peer target for %s\n" ,
440+ pdbg_target_path (target ));
400441 }
401- pdbg_log (PDBG_ERROR , "unable to find the peer target for %s\n" ,
402- pdbg_target_path ( target ) );
442+ pdbg_log (PDBG_ERROR , "Peer class not identified for target class :: %s\n" ,
443+ target -> class );
403444 return NULL ;
404445}
0 commit comments