Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pktmem: Fix warning #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions drivers/pktmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* %LICENSE%
*/

#include "physmmap.h"
#include "pktmem.h"
#include "lwip/mem.h"
Expand All @@ -16,17 +17,17 @@

#include <stdio.h>
#include <string.h>
#include <arch.h>


#define CACHE_LINE_SIZE 64
#define PAGE_SIZE 4096

#define TRUE_LRU 0


#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_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)) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know what is _PAGE_SIZE as its in the arch.h so making this value a constant is misleading . IMHO either this comment should change or LOG2 macro that does LOG2 in proprocessing stage should be added(probably overkill)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't know it's value and use definit oo on from arch.h, because it's target dependent. We need a value provided by arch for mmap/munap to work properly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but the the reason for it being exactly 11 is that we assumed page_size == 4096 at least acoording to the comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, now I understand what you mean

#define PKT_BUF_CACHE_SIZE 16


Expand Down Expand Up @@ -65,8 +66,8 @@ 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));
unsigned which = ((size_t)p & (PAGE_SIZE - 1)) >> PKT_BUF_IDX;
buf_page_head_t *ph = (void *)((uintptr_t)p & ~(_PAGE_SIZE - 1));
unsigned which = ((size_t)p & (_PAGE_SIZE - 1)) >> PKT_BUF_IDX;
unsigned old_mask;

old_mask = ph->free_mask;
Expand All @@ -76,7 +77,7 @@ static void net_freePktBuf(void *p)
if (pkt_bufs_free > PKT_BUF_CACHE_SIZE && ph->free_mask == (1 << PKT_BUF_CNT) - 1) {
if (old_mask)
net_listDel(ph);
munmap(ph, PAGE_SIZE);
munmap(ph, _PAGE_SIZE);
pkt_bufs_free -= PKT_BUF_CNT;
return;
}
Expand Down Expand Up @@ -113,7 +114,7 @@ static ssize_t net_allocPktBuf(void **bufp)
if (!pkt_bufs_free) {
SYS_ARCH_UNPROTECT(old_level);

ph = dmammap(PAGE_SIZE);
ph = dmammap(_PAGE_SIZE);
if (!ph) {
printf("mmap: no memory?\n");
return 0;
Expand Down
Loading