From 1361739c14edd29c5e2e8b69d2bce5f617f2cb96 Mon Sep 17 00:00:00 2001 From: CyrIng Date: Sun, 16 Jul 2023 03:33:25 +0200 Subject: [PATCH] Refactoring for other hardware architectures --- .gitignore | 1 + Makefile | 111 ++++++++++++------ amd_reg.h => x86_64/amd_reg.h | 0 bitasm.h => x86_64/bitasm.h | 0 corefreq-api.h => x86_64/corefreq-api.h | 0 .../corefreq-cli-extra.c | 0 .../corefreq-cli-extra.h | 0 .../corefreq-cli-json.c | 0 .../corefreq-cli-json.h | 0 .../corefreq-cli-rsc-en.h | 0 .../corefreq-cli-rsc-fr.h | 0 .../corefreq-cli-rsc-theme-dflt.h | 0 .../corefreq-cli-rsc-theme-usr1.h | 0 .../corefreq-cli-rsc-theme-usr2.h | 0 .../corefreq-cli-rsc.c | 0 .../corefreq-cli-rsc.h | 0 corefreq-cli.c => x86_64/corefreq-cli.c | 0 corefreq-cli.h => x86_64/corefreq-cli.h | 0 corefreq-ui.c => x86_64/corefreq-ui.c | 0 corefreq-ui.h => x86_64/corefreq-ui.h | 0 corefreq.h => x86_64/corefreq.h | 0 corefreqd.c => x86_64/corefreqd.c | 0 corefreqk.c => x86_64/corefreqk.c | 0 corefreqk.h => x86_64/corefreqk.h | 0 corefreqm.c => x86_64/corefreqm.c | 0 corefreqm.h => x86_64/corefreqm.h | 0 coretypes.h => x86_64/coretypes.h | 0 intel_reg.h => x86_64/intel_reg.h | 0 28 files changed, 79 insertions(+), 33 deletions(-) rename amd_reg.h => x86_64/amd_reg.h (100%) rename bitasm.h => x86_64/bitasm.h (100%) rename corefreq-api.h => x86_64/corefreq-api.h (100%) rename corefreq-cli-extra.c => x86_64/corefreq-cli-extra.c (100%) rename corefreq-cli-extra.h => x86_64/corefreq-cli-extra.h (100%) rename corefreq-cli-json.c => x86_64/corefreq-cli-json.c (100%) rename corefreq-cli-json.h => x86_64/corefreq-cli-json.h (100%) rename corefreq-cli-rsc-en.h => x86_64/corefreq-cli-rsc-en.h (100%) rename corefreq-cli-rsc-fr.h => x86_64/corefreq-cli-rsc-fr.h (100%) rename corefreq-cli-rsc-theme-dflt.h => x86_64/corefreq-cli-rsc-theme-dflt.h (100%) rename corefreq-cli-rsc-theme-usr1.h => x86_64/corefreq-cli-rsc-theme-usr1.h (100%) rename corefreq-cli-rsc-theme-usr2.h => x86_64/corefreq-cli-rsc-theme-usr2.h (100%) rename corefreq-cli-rsc.c => x86_64/corefreq-cli-rsc.c (100%) rename corefreq-cli-rsc.h => x86_64/corefreq-cli-rsc.h (100%) rename corefreq-cli.c => x86_64/corefreq-cli.c (100%) rename corefreq-cli.h => x86_64/corefreq-cli.h (100%) rename corefreq-ui.c => x86_64/corefreq-ui.c (100%) rename corefreq-ui.h => x86_64/corefreq-ui.h (100%) rename corefreq.h => x86_64/corefreq.h (100%) rename corefreqd.c => x86_64/corefreqd.c (100%) rename corefreqk.c => x86_64/corefreqk.c (100%) rename corefreqk.h => x86_64/corefreqk.h (100%) rename corefreqm.c => x86_64/corefreqm.c (100%) rename corefreqm.h => x86_64/corefreqm.h (100%) rename coretypes.h => x86_64/coretypes.h (100%) rename intel_reg.h => x86_64/intel_reg.h (100%) diff --git a/.gitignore b/.gitignore index 4182b04..fc78829 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ corefreq-gui corefreq-cli corefreqd *.keep +build/* diff --git a/Makefile b/Makefile index 4273823..21e4f13 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,11 @@ # Copyright (C) 2015-2023 CYRIL COURTIAT # Licenses: GPL2 +HW = $(shell uname -m) CC ?= cc WARNING = -Wall -Wfatal-errors PWD ?= $(shell pwd) +BUILD ?= build KERNELDIR ?= /lib/modules/$(shell uname -r)/build PREFIX ?= /usr UBENCH = 0 @@ -17,7 +19,10 @@ DELAY_TSC ?= 1 ARCH_PMC ?= obj-m := corefreqk.o -ccflags-y := -D CORE_COUNT=$(CORE_COUNT) \ +corefreqk-y := module/corefreqk.o + +ccflags-y := -I$(PWD)/$(HW) +ccflags-y += -D CORE_COUNT=$(CORE_COUNT) \ -D TASK_ORDER=$(TASK_ORDER) \ -D MAX_FREQ_HZ=$(MAX_FREQ_HZ) ccflags-y += $(WARNING) @@ -82,77 +87,116 @@ LAYOUT += -D UI_TRANSPARENCY=$(UI_TRANSPARENCY) endif .PHONY: all -all: corefreqd corefreq-cli - $(MAKE) -j1 -C $(KERNELDIR) M=$(PWD) modules +all: prepare corefreqd corefreq-cli + @if [ -e $(BUILD)/Makefile ]; then \ + $(MAKE) -j1 -C $(KERNELDIR) M=$(PWD)/$(BUILD) modules; \ + fi + +.PHONY: prepare +prepare: + @if [ ! -d $(BUILD) ]; then \ + mkdir -m +t $(BUILD); \ + fi + @if [ ! -d $(BUILD)/module ]; then \ + mkdir $(BUILD)/module; \ + fi + @if [ ! -e $(BUILD)/Makefile ]; then \ + ln -rs Makefile $(BUILD)/Makefile; \ + fi + @if [ ! -e $(BUILD)/module/corefreqk.c ]; then \ + ln -rs $(HW)/corefreqk.c $(BUILD)/module/corefreqk.c; \ + fi .PHONY: install install: module-install - install -Dm 0755 corefreq-cli corefreqd -t $(PREFIX)/bin + install -Dm 0755 $(BUILD)/corefreq-cli $(BUILD)/corefreqd \ + -t $(PREFIX)/bin install -Dm 0644 corefreqd.service \ $(PREFIX)/lib/systemd/system/corefreqd.service .PHONY: module-install module-install: - $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install + $(MAKE) -C $(KERNELDIR) M=$(PWD)/$(BUILD) modules_install .PHONY: clean clean: - rm -f corefreqd corefreq-cli - $(MAKE) -j1 -C $(KERNELDIR) M=$(PWD) clean + @if [ -e $(BUILD)/Makefile ]; then \ + $(MAKE) -j1 -C $(KERNELDIR) M=$(PWD)/$(BUILD) clean; \ + fi + @if [ -e $(BUILD)/corefreqd ]; then \ + rm -f $(BUILD)/corefreqd; \ + fi + @if [ -e $(BUILD)/corefreq-cli ]; then \ + rm -f $(BUILD)/corefreq-cli; \ + fi + @if [ -e $(BUILD)/module/corefreqk.c ]; then \ + rm -f $(BUILD)/module/corefreqk.c; \ + fi + @if [ -e $(BUILD)/Makefile ]; then \ + rm -f $(BUILD)/Makefile; \ + fi + @if [ -d $(BUILD)/module ]; then \ + rmdir $(BUILD)/module; \ + fi + @if [ -d $(BUILD) ] && [ -z "$(ls -A $(BUILD))" ]; then \ + rmdir $(BUILD); \ + fi -corefreqm.o: corefreqm.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreqm.c \ +corefreqm.o: $(HW)/corefreqm.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreqm.c \ $(DEFINITIONS) \ - -o corefreqm.o + -o $(BUILD)/corefreqm.o -corefreqd.o: corefreqd.c - $(CC) $(OPTIM_FLG) $(WARNING) -pthread -c corefreqd.c \ +corefreqd.o: $(HW)/corefreqd.c + $(CC) $(OPTIM_FLG) $(WARNING) -pthread -c $(HW)/corefreqd.c \ $(DEFINITIONS) \ - -o corefreqd.o + -o $(BUILD)/corefreqd.o corefreqd: corefreqd.o corefreqm.o - $(CC) $(OPTIM_FLG) $(WARNING) corefreqd.c corefreqm.c \ + $(CC) $(OPTIM_FLG) $(WARNING) $(HW)/corefreqd.c $(HW)/corefreqm.c \ $(DEFINITIONS) \ - -o corefreqd -lpthread -lm -lrt + -o $(BUILD)/corefreqd -lpthread -lm -lrt -corefreq-ui.o: corefreq-ui.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreq-ui.c \ +corefreq-ui.o: $(HW)/corefreq-ui.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreq-ui.c \ $(DEFINITIONS) \ - -o corefreq-ui.o + -o $(BUILD)/corefreq-ui.o -corefreq-cli.o: corefreq-cli.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreq-cli.c \ +corefreq-cli.o: $(HW)/corefreq-cli.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreq-cli.c \ $(DEFINITIONS) $(LAYOUT) \ - -o corefreq-cli.o + -o $(BUILD)/corefreq-cli.o -corefreq-cli-rsc.o: corefreq-cli-rsc.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreq-cli-rsc.c \ +corefreq-cli-rsc.o: $(HW)/corefreq-cli-rsc.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreq-cli-rsc.c \ $(DEFINITIONS) $(LAYOUT) \ - -o corefreq-cli-rsc.o + -o $(BUILD)/corefreq-cli-rsc.o -corefreq-cli-json.o: corefreq-cli-json.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreq-cli-json.c \ +corefreq-cli-json.o: $(HW)/corefreq-cli-json.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreq-cli-json.c \ $(DEFINITIONS) \ - -o corefreq-cli-json.o + -o $(BUILD)/corefreq-cli-json.o -corefreq-cli-extra.o: corefreq-cli-extra.c - $(CC) $(OPTIM_FLG) $(WARNING) -c corefreq-cli-extra.c \ +corefreq-cli-extra.o: $(HW)/corefreq-cli-extra.c + $(CC) $(OPTIM_FLG) $(WARNING) -c $(HW)/corefreq-cli-extra.c \ $(DEFINITIONS) \ - -o corefreq-cli-extra.o + -o $(BUILD)/corefreq-cli-extra.o corefreq-cli: corefreq-cli.o corefreq-ui.o corefreq-cli-rsc.o \ corefreq-cli-json.o corefreq-cli-extra.o $(CC) $(OPTIM_FLG) $(WARNING) \ - corefreq-cli.c corefreq-ui.c corefreq-cli-rsc.c \ - corefreq-cli-json.c corefreq-cli-extra.c \ + $(HW)/corefreq-cli.c $(HW)/corefreq-ui.c $(HW)/corefreq-cli-rsc.c \ + $(HW)/corefreq-cli-json.c $(HW)/corefreq-cli-extra.c \ $(DEFINITIONS) $(LAYOUT) \ - -o corefreq-cli -lm -lrt + -o $(BUILD)/corefreq-cli -lm -lrt .PHONY: info info: + $(info HW [$(HW)]) $(info CC [$(shell whereis -b $(CC))]) $(info WARNING [$(WARNING)]) $(info PWD [$(PWD)]) + $(info BUILD [$(BUILD)]) $(info KERNELDIR [$(KERNELDIR)]) $(info PREFIX [$(PREFIX)]) $(info LEGACY [$(LEGACY)]) @@ -167,6 +211,7 @@ info: $(info NO_FOOTER [$(NO_FOOTER)]) $(info NO_UPPER [$(NO_UPPER)]) $(info NO_LOWER [$(NO_LOWER)]) + @echo -n .PHONY: help help: diff --git a/amd_reg.h b/x86_64/amd_reg.h similarity index 100% rename from amd_reg.h rename to x86_64/amd_reg.h diff --git a/bitasm.h b/x86_64/bitasm.h similarity index 100% rename from bitasm.h rename to x86_64/bitasm.h diff --git a/corefreq-api.h b/x86_64/corefreq-api.h similarity index 100% rename from corefreq-api.h rename to x86_64/corefreq-api.h diff --git a/corefreq-cli-extra.c b/x86_64/corefreq-cli-extra.c similarity index 100% rename from corefreq-cli-extra.c rename to x86_64/corefreq-cli-extra.c diff --git a/corefreq-cli-extra.h b/x86_64/corefreq-cli-extra.h similarity index 100% rename from corefreq-cli-extra.h rename to x86_64/corefreq-cli-extra.h diff --git a/corefreq-cli-json.c b/x86_64/corefreq-cli-json.c similarity index 100% rename from corefreq-cli-json.c rename to x86_64/corefreq-cli-json.c diff --git a/corefreq-cli-json.h b/x86_64/corefreq-cli-json.h similarity index 100% rename from corefreq-cli-json.h rename to x86_64/corefreq-cli-json.h diff --git a/corefreq-cli-rsc-en.h b/x86_64/corefreq-cli-rsc-en.h similarity index 100% rename from corefreq-cli-rsc-en.h rename to x86_64/corefreq-cli-rsc-en.h diff --git a/corefreq-cli-rsc-fr.h b/x86_64/corefreq-cli-rsc-fr.h similarity index 100% rename from corefreq-cli-rsc-fr.h rename to x86_64/corefreq-cli-rsc-fr.h diff --git a/corefreq-cli-rsc-theme-dflt.h b/x86_64/corefreq-cli-rsc-theme-dflt.h similarity index 100% rename from corefreq-cli-rsc-theme-dflt.h rename to x86_64/corefreq-cli-rsc-theme-dflt.h diff --git a/corefreq-cli-rsc-theme-usr1.h b/x86_64/corefreq-cli-rsc-theme-usr1.h similarity index 100% rename from corefreq-cli-rsc-theme-usr1.h rename to x86_64/corefreq-cli-rsc-theme-usr1.h diff --git a/corefreq-cli-rsc-theme-usr2.h b/x86_64/corefreq-cli-rsc-theme-usr2.h similarity index 100% rename from corefreq-cli-rsc-theme-usr2.h rename to x86_64/corefreq-cli-rsc-theme-usr2.h diff --git a/corefreq-cli-rsc.c b/x86_64/corefreq-cli-rsc.c similarity index 100% rename from corefreq-cli-rsc.c rename to x86_64/corefreq-cli-rsc.c diff --git a/corefreq-cli-rsc.h b/x86_64/corefreq-cli-rsc.h similarity index 100% rename from corefreq-cli-rsc.h rename to x86_64/corefreq-cli-rsc.h diff --git a/corefreq-cli.c b/x86_64/corefreq-cli.c similarity index 100% rename from corefreq-cli.c rename to x86_64/corefreq-cli.c diff --git a/corefreq-cli.h b/x86_64/corefreq-cli.h similarity index 100% rename from corefreq-cli.h rename to x86_64/corefreq-cli.h diff --git a/corefreq-ui.c b/x86_64/corefreq-ui.c similarity index 100% rename from corefreq-ui.c rename to x86_64/corefreq-ui.c diff --git a/corefreq-ui.h b/x86_64/corefreq-ui.h similarity index 100% rename from corefreq-ui.h rename to x86_64/corefreq-ui.h diff --git a/corefreq.h b/x86_64/corefreq.h similarity index 100% rename from corefreq.h rename to x86_64/corefreq.h diff --git a/corefreqd.c b/x86_64/corefreqd.c similarity index 100% rename from corefreqd.c rename to x86_64/corefreqd.c diff --git a/corefreqk.c b/x86_64/corefreqk.c similarity index 100% rename from corefreqk.c rename to x86_64/corefreqk.c diff --git a/corefreqk.h b/x86_64/corefreqk.h similarity index 100% rename from corefreqk.h rename to x86_64/corefreqk.h diff --git a/corefreqm.c b/x86_64/corefreqm.c similarity index 100% rename from corefreqm.c rename to x86_64/corefreqm.c diff --git a/corefreqm.h b/x86_64/corefreqm.h similarity index 100% rename from corefreqm.h rename to x86_64/corefreqm.h diff --git a/coretypes.h b/x86_64/coretypes.h similarity index 100% rename from coretypes.h rename to x86_64/coretypes.h diff --git a/intel_reg.h b/x86_64/intel_reg.h similarity index 100% rename from intel_reg.h rename to x86_64/intel_reg.h