Skip to content

Commit b851e01

Browse files
committed
Add Peer target support
1 parent 2250380 commit b851e01

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

libpdbg/device.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,36 @@ static void dt_link_virtual(struct pdbg_target *node, struct pdbg_target *vnode)
657657
vnode->vnode = node;
658658
}
659659

660+
static void dt_link_peer(struct pdbg_target *node, struct pdbg_target *pnode)
661+
{
662+
node->pnode = pnode;
663+
pnode->pnode = node;
664+
}
665+
666+
667+
static void pdbg_targets_init_peer(struct pdbg_target *node, struct pdbg_target *root)
668+
{
669+
struct pdbg_target *child = NULL;
670+
671+
/* Skip virtual nodes */
672+
if (target_is_virtual(node))
673+
goto skip;
674+
675+
struct pdbg_target *pnode = NULL;
676+
pnode = pdbg_get_peer_target(node);
677+
678+
if (!pnode)
679+
goto skip;
680+
681+
dt_link_peer(node, pnode);
682+
683+
skip:
684+
list_for_each(&node->children, child, list) {
685+
pdbg_targets_init_peer(child, root);
686+
}
687+
}
688+
689+
660690
static void pdbg_targets_init_virtual(struct pdbg_target *node, struct pdbg_target *root)
661691
{
662692
struct pdbg_target *vnode, *child = NULL;
@@ -803,6 +833,8 @@ bool pdbg_targets_init(void *fdt)
803833

804834
pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);
805835

836+
pdbg_targets_init_peer(pdbg_dt_root, pdbg_dt_root);
837+
806838
//Close any FDs which might be still opened
807839
close(dtb->system.fd);
808840
close(dtb->backend.fd);

libpdbg/libpdbg.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
static pdbg_progress_tick_t progress_tick;
88
static 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+
1023
struct pdbg_target *get_parent(struct pdbg_target *target, bool system)
1124
{
1225
struct pdbg_target *parent;
@@ -359,3 +372,72 @@ bool pdbg_context_is_short(void)
359372
{
360373
return pdbg_short_context;
361374
}
375+
376+
char* extract_string_after_colon(char* input)
377+
{
378+
// Find the position of ':'
379+
char* pos = strchr(input, ':');
380+
// Return pointer to substring after ':'
381+
if (pos != NULL && *(pos + 1) != '\0') {
382+
return pos + 1;
383+
}
384+
// Return empty string if ':' is not found or nothing follows it
385+
return "";
386+
}
387+
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+
405+
struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target)
406+
{
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)
413+
{
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
422+
{
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+
}
435+
}
436+
}
437+
438+
}
439+
pdbg_log(PDBG_ERROR, "unable to find the peer target for %s\n",
440+
pdbg_target_path(target));
441+
}
442+
return NULL;
443+
}

libpdbg/libpdbg.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,20 @@ bool pdbg_context_short(void);
15301530
*/
15311531
void pdbg_release_dt_root();
15321532

1533+
/**
1534+
* @brief Find a peer target of the given class
1535+
* @param[in] target the pdbg_target
1536+
* @return struct pdbg_target* of the peer class
1537+
*/
1538+
struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target);
1539+
1540+
/**
1541+
* @brief Helper method to return the peer node of the target
1542+
* @param[in] target the pdbg_target
1543+
* @return struct pdbg_target* of the peer class
1544+
*/
1545+
struct pdbg_target *pdbg_get_pnode(struct pdbg_target *target);
1546+
15331547
#ifdef __cplusplus
15341548
}
15351549
#endif

libpdbg/target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct pdbg_target {
6262
struct list_node class_link;
6363
void *priv;
6464
struct pdbg_target *vnode;
65+
struct pdbg_target *pnode;
6566
};
6667

6768
struct pdbg_mfile {

0 commit comments

Comments
 (0)