Skip to content

Commit

Permalink
drivers/pktmem: adjust allocPktBuf and freePktBuf
Browse files Browse the repository at this point in the history
adjust packet buffer handling for targets with page size less than packet buffer size
JIRA: RTOS-507
  • Loading branch information
julianuziemblo committed Sep 17, 2024
1 parent ab5a8c7 commit ccc4d77
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions drivers/pktmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@
#include <string.h>


// FIXME: transfer to appropriate file with platform-specific definitions
#if defined(__ARM_ARCH_7EM__)
#define CACHE_LINE_SIZE 32
#else
#define CACHE_LINE_SIZE 64
#define PAGE_SIZE 4096
#endif

#define TRUE_LRU 0

#define PKT_BUF_SIZE (2048 - CACHE_LINE_SIZE)

#if PAGE_SIZE < PKT_BUF_SIZE
#define PKT_BUF_CNT 1
#else
#define PKT_BUF_CNT (size_t)((PAGE_SIZE - CACHE_LINE_SIZE) / PKT_BUF_SIZE)
#define PKT_BUF_IDX 11 /* log2(PAGE_SIZE) - ceil(log2(PKT_BUF_CNT)) */
#endif

#define PKT_BUF_SIZE (2048 - CACHE_LINE_SIZE)
#define PKT_BUF_CNT (size_t)((PAGE_SIZE - CACHE_LINE_SIZE) / PKT_BUF_SIZE)
#define PKT_BUF_IDX 11 /* log2(PAGE_SIZE) - ceil(log2(PKT_BUF_CNT)) */
#define PKT_BUF_CACHE_SIZE 16


Expand Down Expand Up @@ -65,7 +74,11 @@ static void net_listDel(buf_page_head_t *ph)
static void net_freePktBuf(void *p)
{
buf_page_head_t *ph = (void *)((uintptr_t)p & ~(PAGE_SIZE - 1));
#if PAGE_SIZE < PKT_BUF_SIZE
unsigned which = 0;
#else
unsigned which = ((size_t)p & (PAGE_SIZE - 1)) >> PKT_BUF_IDX;
#endif
unsigned old_mask;

old_mask = ph->free_mask;
Expand Down Expand Up @@ -114,7 +127,11 @@ static ssize_t net_allocPktBuf(void **bufp)
if (pkt_bufs_free == 0) {
SYS_ARCH_UNPROTECT(old_level);

#if PAGE_SIZE < PKT_BUF_SIZE
ph = dmammap(PKT_BUF_SIZE);
#else
ph = dmammap(PAGE_SIZE);
#endif
if (ph == NULL) {
printf("mmap: no memory?\n");
return 0;
Expand Down

0 comments on commit ccc4d77

Please sign in to comment.