Skip to content

Commit

Permalink
Merge pull request #1 from intel-retail/add_code
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
jstein13 authored Apr 18, 2023
2 parents f42aac8 + b8f2dfa commit c1a76cc
Show file tree
Hide file tree
Showing 11 changed files with 1,389 additions and 0 deletions.
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: MIT
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: MIT

#DIRS = $(shell find . -maxdepth 1 -type d -not -path "./.git" \
# -not -path "." -not -path "./release" -not -path "./cmn" | sort)
DIRS = lib synctest
.PHONY: $(DIRS)

MAKE += --no-print-directory
CFLAGS =-g
all:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir; \
done

debug:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir debug; \
done

clean:
@for dir in $(DIRS); do \
$(MAKE) -C $$dir clean; \
done

distclean:
@rm -rf release

release: distclean
@$(MAKE) clean
@$(MAKE)
@mkdir release
@cp lib/*.so synctest/synctest release
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2023 Intel Corporation
SPDX-License-Identifier: MIT

This program allows a system to alter their vertical sync firing times.
This is sample code only and is only supported on 11th Gen Core.

Building steps:
1) sudo apt install libdrm-dev libpciaccess-dev
1) Type 'make release' from the main directory. It compiles everything and creates a
release folder which can then be copied to the target systems.

Building of this program has been succesfully tested on both Ubuntu 20 and Fedora 30.

Installing and running the programs:
1) On the system, go to the directory where these files exist and set environment variable:
export LD_LIBRARY_PATH=.
2) On the primary system, run it as follows:
./synctest
(Note by default this is set to move vsync by 1.0 ms.)
69 changes: 69 additions & 0 deletions cmn/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: MIT

#ifndef _DEBUG_H
#define _DEBUG_H

#include <stdio.h>

enum {
ERR,
INFO,
DBG,
TRACE,
};

/*
* Set it to 0 or higher with 0 being lowest number of messages
* 0 = Only errors show up
* 1 = Errors + Info messages
* 2 = Errors + Info messages + Debug messages
* 3 = Errors + Info messages + Debug messages + Trace calls
*/
static int dbg_lvl = INFO;

#define _PRINT(prefix, fmt, ...) \
if(1) {\
printf("%s", prefix); \
printf(fmt, ##__VA_ARGS__); \
fflush(stdout); \
}

#define PRINT(fmt, ...) _PRINT("", fmt, ##__VA_ARGS__)
#define ERR(fmt, ...) _PRINT("[Error] ", fmt, ##__VA_ARGS__)
#define WARNING(fmt, ...) _PRINT("[Warning] ", fmt, ##__VA_ARGS__)
#define DBG(fmt, ...) if(dbg_lvl >= DBG) _PRINT("[DBG] ", fmt, ##__VA_ARGS__)
#define INFO(fmt, ...) if(dbg_lvl >= INFO) _PRINT("[Info] ", fmt, ##__VA_ARGS__)
#define TRACE(fmt, ...) if(dbg_lvl >= TRACE) PRINT(fmt, ##__VA_ARGS__)

#ifdef __cplusplus
#define TRACING() tracer trace(__FUNCTION__);
#else
#define TRACING()
#endif

#ifdef __cplusplus
class tracer {
private:
char *m_func_name;
public:
tracer(const char *func_name)
{
TRACE(">>> %s\n", func_name);
m_func_name = (char *) func_name;
}
~tracer() { TRACE("<<< %s\n", m_func_name); }
};
#endif

inline int set_dbg_lvl(int lvl)
{
int ret = 1;
if(lvl >= ERR && lvl <= TRACE) {
dbg_lvl = lvl;
ret = 0;
}
return ret;
}

#endif
16 changes: 16 additions & 0 deletions cmn/vsyncalter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: MIT

#ifndef _VSYNCALTER_H
#define _VSYNCALTER_H

#define ONE_VSYNC_PERIOD_IN_MS 16.666
#define MAX_TIMESTAMPS 100

int vsync_lib_init();
void vsync_lib_uninit();
void synchronize_vsync(double time_diff);
int get_vsync(long *vsync_array, int size);
int find_enabled_combo_phys();

#endif
43 changes: 43 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: MIT

export PWD=$(shell pwd)
BINNAME=libvsyncalter.so
MAKE += --no-print-directory
export CC=g++
export DBG_FLAGS?=-Ofast
export LIBS=-lrt -ldrm -lpciaccess
export INCLUDES=-I../cmn -I/usr/include/drm
export CFLAGS=-c -fPIC
export LFLAGS=-Wall
export HEADERS=$(wildcard *.h)
export SOURCES=$(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)

all::
@echo "Compiling..."

all::$(SOURCES) $(BINNAME)

all::
@echo "Done"

$(BINNAME): $(OBJECTS)
@$(CC) $(DBG_FLAGS) $(LFLAGS) -shared -o $@ $(OBJECTS) $(LIBS)
@if [ "$(DBG_FLAGS)" = "" ]; then \
echo "Stripping $@"; \
strip -x $@; \
fi

.cpp.o: $(HEADERS)
@echo $<
@$(CC) $(DBG_FLAGS) $(CFLAGS) $(LFLAGS) $(INCLUDES) $<

debug:
@export DBG_FLAGS='-g'; \
$(MAKE)

clean:
@echo "Cleaning..."
@rm -f $(BINNAME) *.o

Loading

0 comments on commit c1a76cc

Please sign in to comment.