Skip to content

Commit

Permalink
Add Peer target support
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakala-k committed Feb 20, 2025
1 parent 239467a commit 09801bc
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
32 changes: 32 additions & 0 deletions libpdbg/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,36 @@ static void dt_link_virtual(struct pdbg_target *node, struct pdbg_target *vnode)
vnode->vnode = node;
}

static void dt_link_peer(struct pdbg_target *node, struct pdbg_target *pnode)
{
node->pnode = pnode;
pnode->pnode = node;
}


static void pdbg_targets_init_peer(struct pdbg_target *node, struct pdbg_target *root)
{
struct pdbg_target *child = NULL;

/* Skip virtual nodes */
if (target_is_virtual(node))
goto skip;

struct pdbg_target *pnode = NULL;
pnode = pdbg_get_peer_target(node);

if (!pnode)
goto skip;

dt_link_peer(node, pnode);

skip:
list_for_each(&node->children, child, list) {
pdbg_targets_init_peer(child, root);
}
}


static void pdbg_targets_init_virtual(struct pdbg_target *node, struct pdbg_target *root)
{
struct pdbg_target *vnode, *child = NULL;
Expand Down Expand Up @@ -803,6 +833,8 @@ bool pdbg_targets_init(void *fdt)

pdbg_targets_init_virtual(pdbg_dt_root, pdbg_dt_root);

pdbg_targets_init_peer(pdbg_dt_root, pdbg_dt_root);

//Close any FDs which might be still opened
close(dtb->system.fd);
close(dtb->backend.fd);
Expand Down
82 changes: 82 additions & 0 deletions libpdbg/libpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
static pdbg_progress_tick_t progress_tick;
static bool pdbg_short_context = false;

#define MAX_PEER_TYPE_ENTRIES 3

typedef struct {
char key[120];
char value[120];
} peer_map_struct;

peer_map_struct peer_map[MAX_PEER_TYPE_ENTRIES] = {
{"tbusl", "tbusl"},
{"core", "l3cache"},
{"l3cache", "core"},
};

struct pdbg_target *get_parent(struct pdbg_target *target, bool system)
{
struct pdbg_target *parent;
Expand Down Expand Up @@ -359,3 +372,72 @@ bool pdbg_context_is_short(void)
{
return pdbg_short_context;
}

char* extract_string_after_colon(char* input)
{
// Find the position of ':'
char* pos = strchr(input, ':');
// Return pointer to substring after ':'
if (pos != NULL && *(pos + 1) != '\0') {
return pos + 1;
}
// Return empty string if ':' is not found or nothing follows it
return "";
}


// Function to get peer class name
const char* get_peer_class_name(const char *key) {

for (int i = 0; i < MAX_PEER_TYPE_ENTRIES; i++) {
if (strcmp(peer_map[i].key, key) == 0) {
return peer_map[i].value;
}
}
return NULL; // Key not found
}

struct pdbg_target *pdbg_get_pnode(struct pdbg_target *target)
{
return target->pnode;
}

struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target)
{
//Get the class type to find its appropriate peer
const char* peer_class_name = get_peer_class_name(target->class);

//As get attr is an expensive operation, check if the current class
//is expected to have a peer class
if(peer_class_name)
{
char tgtPeerPath[120];
if (!pdbg_target_get_attribute(target, "ATTR_PEER_PATH", 1, 120,
tgtPeerPath)) {
//unable to find the path
pdbg_log(PDBG_ERROR, "unable to find the attribute ATTR_PEER_PATH for %s\n",
pdbg_target_path(target));
}
else
{
struct pdbg_target *traversed_target;
//The peer could only be of the same type, so look for all the targets of that type
pdbg_for_each_class_target(peer_class_name, traversed_target)
{
char tgtPhyPath[120];
if (pdbg_target_get_attribute(traversed_target, "ATTR_PHYS_DEV_PATH", 1, 120,
tgtPhyPath)) {
//unable to find the path
if( strcmp(extract_string_after_colon(tgtPhyPath), extract_string_after_colon(tgtPeerPath)) == 0)
{
return traversed_target;
}
}
}

}
pdbg_log(PDBG_ERROR, "unable to find the peer target for %s\n",
pdbg_target_path(target));
}
return NULL;
}
14 changes: 14 additions & 0 deletions libpdbg/libpdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,20 @@ bool pdbg_context_short(void);
*/
void pdbg_release_dt_root();

/**
* @brief Find a peer target of the given class
* @param[in] target the pdbg_target
* @return struct pdbg_target* of the peer class
*/
struct pdbg_target *pdbg_get_peer_target(struct pdbg_target *target);

/**
* @brief Helper method to return the peer node of the target
* @param[in] target the pdbg_target
* @return struct pdbg_target* of the peer class
*/
struct pdbg_target *pdbg_get_pnode(struct pdbg_target *target);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions libpdbg/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct pdbg_target {
struct list_node class_link;
void *priv;
struct pdbg_target *vnode;
struct pdbg_target *pnode;
};

struct pdbg_mfile {
Expand Down

0 comments on commit 09801bc

Please sign in to comment.