Skip to content

Commit

Permalink
Set name attribute for DMA allocated buffer
Browse files Browse the repository at this point in the history
DMA heap allows to set name for dmabufs. Set name attribute for DMA
allocated buffer to differentiate between heap and non-heap allocation.

Name string updates as follows.
Heap      ->  dsp_<pid>_<tid>_<remote flags>
Non-Heap  ->  apps_<pid>_<tid>_<rpcflags>

Signed-off-by: Bharath Kumar V <[email protected]>
  • Loading branch information
quic-bkumar committed Jul 29, 2024
1 parent 2d88a00 commit f0f1daa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
7 changes: 7 additions & 0 deletions inc/fastrpc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,11 @@ int fastrpc_config_get_caller_stack_num(void);
**/
int fastrpc_config_init();

/*
* fastrpc_config_is_setdmabufname_enabled() - Check if DMA allocated buffer
* name attribute debug support has been requested.
* Returns: True or False, status of debug support
*/
boolean fastrpc_config_is_setdmabufname_enabled(void);

#endif /*__FASTRPC_CONFIG_H__*/
16 changes: 16 additions & 0 deletions inc/rpcmem_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

#include "rpcmem.h"

/*
* rpcmem_set_dmabuf_name() - API to set name for DMA allocated buffer.
* Name string updates as follows.
* Heap : dsp_<pid>_<tid>_<remote-flags>
* Non-heap : apps_<pid>_<tid>_<rpcflags>
*
* @name : Pointer to string, "dsp" for heap buffers, "apps" for
* non-heap buffers
* @fd : File descriptor of buffer
* @heapid : Heap ID used for memory allocation
* @buf : Pointer to buffer start address
* @rpcflags: Memory flags describing attributes of allocation
* Return : 0 on success, valid non-zero error code on failure
*/
int rpcmem_set_dmabuf_name(const char *name, int fd, int heapid,
void *buf, uint32 rpc_flags);
/*
* returns an file descriptor associated with the address
*/
Expand Down
3 changes: 2 additions & 1 deletion src/apps_mem_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ __QAIC_IMPL(apps_mem_request_map64)(int heapid, uint32 lflags, uint32 rflags,
VERIFYC(NULL != (buf = rpcmem_alloc_internal(heapid, lflags, len)),
AEE_ENORPCMEMORY);
VERIFYC(0 < (fd = rpcmem_to_fd_internal(buf)), AEE_EBADFD);

rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags);
/* Using FASTRPC_MAP_FD_DELAYED as only HLOS mapping is reqd at this point
*/
VERIFY(AEE_SUCCESS == (nErr = fastrpc_mmap(domain, fd, buf, 0, len,
Expand Down Expand Up @@ -140,6 +140,7 @@ __QAIC_IMPL(apps_mem_request_map64)(int heapid, uint32 lflags, uint32 rflags,
AEE_ENORPCMEMORY);
fd = rpcmem_to_fd_internal(buf);
VERIFYC(fd > 0, AEE_EBADPARM);
rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags);
}
VERIFY(AEE_SUCCESS ==
(nErr = remote_mmap64_internal(fd, rflags, (uint64_t)buf, len,
Expand Down
10 changes: 10 additions & 0 deletions src/fastrpc_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct fastrpc_config_param {
boolean logPackets;
int leak_detect;
int num_call_stack;
boolean setdmabufname;
};

static struct fastrpc_config_param frpc_config;
Expand Down Expand Up @@ -261,6 +262,11 @@ int fastrpc_read_config_file_from_path(const char *base, const char *file) {
FARF(ALWAYS, "fastrpc config setting call stack num with %d\n",
frpc_config.num_call_stack);
}
} else if (std_strncmp(param, CONFIG_SETDMABUFNAME,
std_strlen(CONFIG_SETDMABUFNAME)) == 0) {
param = strtok_r (NULL, delim, &saveptr);
if (param != NULL && atoi(param))
frpc_config.setdmabufname = TRUE;
}
param = NULL;
} while (!eof);
Expand Down Expand Up @@ -348,6 +354,10 @@ int fastrpc_config_get_caller_stack_num(void) {
return frpc_config.num_call_stack;
}

boolean fastrpc_config_is_setdmabufname_enabled(void) {
return frpc_config.setdmabufname;
}

// Fastrpc config init function
int fastrpc_config_init() {
int nErr = AEE_SUCCESS, i = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/rpcmem_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ void rpcmem_deinit() {
pthread_mutex_destroy(&rpcmt);
}

int rpcmem_set_dmabuf_name(const char *name, int fd, int heapid,
void *buf, uint32 rpcflags) {
// Dummy call where DMABUF is not used
return 0;
}

int rpcmem_to_fd_internal(void *po) {
struct rpc_info *rinfo, *rfree = 0;
QNode *pn, *pnn;
Expand Down

0 comments on commit f0f1daa

Please sign in to comment.