aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authornotaz2012-08-19 22:39:49 +0300
committernotaz2012-10-12 00:05:08 +0300
commit9ee0fd5b333039b1140d90f935aa9299825f1e42 (patch)
tree5fa0d39647613e0e5b4ea3d582b91ecbc3e1ae91 /frontend
parent50f9355a2338111d940ed408f52fe1defe4df23e (diff)
downloadpcsx_rearmed-9ee0fd5b333039b1140d90f935aa9299825f1e42.tar.gz
pcsx_rearmed-9ee0fd5b333039b1140d90f935aa9299825f1e42.tar.bz2
pcsx_rearmed-9ee0fd5b333039b1140d90f935aa9299825f1e42.zip
start mmap'ing vram, with hugetlb if possible
Diffstat (limited to 'frontend')
-rw-r--r--frontend/common/plat.h4
-rw-r--r--frontend/linux/plat.c47
-rw-r--r--frontend/plugin_lib.c13
-rw-r--r--frontend/plugin_lib.h2
4 files changed, 61 insertions, 5 deletions
diff --git a/frontend/common/plat.h b/frontend/common/plat.h
index 0a9fc0b..416f8ac 100644
--- a/frontend/common/plat.h
+++ b/frontend/common/plat.h
@@ -45,6 +45,10 @@ int plat_is_dir(const char *path);
int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
void plat_sleep_ms(int ms);
+void *plat_mmap(unsigned long addr, size_t size, int need_exec);
+void *plat_mremap(void *ptr, size_t oldsize, size_t newsize);
+void plat_munmap(void *ptr, size_t size);
+
/* timers, to be used for time diff and must refer to the same clock */
unsigned int plat_get_ticks_ms(void);
unsigned int plat_get_ticks_us(void);
diff --git a/frontend/linux/plat.c b/frontend/linux/plat.c
index b7152b5..044084e 100644
--- a/frontend/linux/plat.c
+++ b/frontend/linux/plat.c
@@ -17,9 +17,17 @@
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
+#include <errno.h>
#include "../common/plat.h"
+/* XXX: maybe unhardcode pagesize? */
+#define HUGETLB_PAGESIZE (2 * 1024 * 1024)
+#define HUGETLB_THRESHOLD (HUGETLB_PAGESIZE / 2)
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB 0x40000 /* arch specific */
+#endif
+
int plat_is_dir(const char *path)
{
@@ -126,16 +134,34 @@ int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
return ret;
}
-void *plat_mmap(unsigned long addr, size_t size)
+void *plat_mmap(unsigned long addr, size_t size, int need_exec)
{
+ static int hugetlb_disabled;
+ int prot = PROT_READ | PROT_WRITE;
+ int flags = MAP_PRIVATE | MAP_ANONYMOUS;
void *req, *ret;
req = (void *)addr;
- ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ if (need_exec)
+ prot |= PROT_EXEC;
+ if (size >= HUGETLB_THRESHOLD && !hugetlb_disabled)
+ flags |= MAP_HUGETLB;
+
+ ret = mmap(req, size, prot, flags, -1, 0);
+ if (ret == MAP_FAILED && (flags & MAP_HUGETLB)) {
+ fprintf(stderr,
+ "warning: failed to do hugetlb mmap (%p, %zu): %d\n",
+ req, size, errno);
+ hugetlb_disabled = 1;
+ flags &= ~MAP_HUGETLB;
+ ret = mmap(req, size, prot, flags, -1, 0);
+ }
if (ret == MAP_FAILED)
return NULL;
- if (ret != req)
- printf("warning: mmaped to %p, requested %p\n", ret, req);
+
+ if (req != NULL && ret != req)
+ fprintf(stderr,
+ "warning: mmaped to %p, requested %p\n", ret, req);
return ret;
}
@@ -155,7 +181,18 @@ void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
void plat_munmap(void *ptr, size_t size)
{
- munmap(ptr, size);
+ int ret;
+
+ ret = munmap(ptr, size);
+ if (ret != 0 && (size & (HUGETLB_PAGESIZE - 1))) {
+ // prehaps an autorounded hugetlb mapping?
+ size = (size + HUGETLB_PAGESIZE - 1) & ~(HUGETLB_PAGESIZE - 1);
+ ret = munmap(ptr, size);
+ }
+ if (ret != 0) {
+ fprintf(stderr,
+ "munmap(%p, %zu) failed: %d\n", ptr, size, errno);
+ }
}
/* lprintf */
diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c
index 4dbb9a7..c2e2ab4 100644
--- a/frontend/plugin_lib.c
+++ b/frontend/plugin_lib.c
@@ -21,6 +21,7 @@
#include "linux/fbdev.h"
#include "common/fonts.h"
#include "common/input.h"
+#include "common/plat.h"
#include "menu.h"
#include "main.h"
#include "plat.h"
@@ -484,12 +485,24 @@ static void pl_get_layer_pos(int *x, int *y, int *w, int *h)
*h = g_layer_h;
}
+static void *pl_mmap(unsigned int size)
+{
+ return plat_mmap(0, size, 0);
+}
+
+static void pl_munmap(void *ptr, unsigned int size)
+{
+ plat_munmap(ptr, size);
+}
+
struct rearmed_cbs pl_rearmed_cbs = {
pl_get_layer_pos,
pl_vout_open,
pl_vout_set_mode,
pl_vout_flip,
pl_vout_close,
+ pl_mmap,
+ pl_munmap,
};
/* watchdog */
diff --git a/frontend/plugin_lib.h b/frontend/plugin_lib.h
index 7687bf8..1701d06 100644
--- a/frontend/plugin_lib.h
+++ b/frontend/plugin_lib.h
@@ -44,6 +44,8 @@ struct rearmed_cbs {
void *(*pl_vout_set_mode)(int w, int h, int bpp);
void *(*pl_vout_flip)(void);
void (*pl_vout_close)(void);
+ void *(*mmap)(unsigned int size);
+ void (*munmap)(void *ptr, unsigned int size);
// these are only used by some frontends
void (*pl_vout_raw_flip)(int x, int y);
void (*pl_vout_set_raw_vram)(void *vram);