feat(lab05): add files
This commit is contained in:
5
src/05-optimization/Makefile
Normal file
5
src/05-optimization/Makefile
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
DIRS=$(filter-out Makefile, $(wildcard *))
|
||||||
|
|
||||||
|
all clean install clean_all:
|
||||||
|
for dir in $(DIRS); do $(MAKE) $@ -C $$dir; done
|
||||||
|
|
||||||
54
src/05-optimization/clock/Makefile
Normal file
54
src/05-optimization/clock/Makefile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
EXE=clock
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O0 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
56
src/05-optimization/clock/clock.c
Normal file
56
src/05-optimization/clock/clock.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
void measure (int mode, int samples)
|
||||||
|
{
|
||||||
|
struct timespec start_time;
|
||||||
|
struct timespec stop_time;
|
||||||
|
clock_gettime (mode, &start_time); // setup...
|
||||||
|
clock_gettime (mode, &start_time);
|
||||||
|
for (int i = 0; i<samples; i++)
|
||||||
|
{
|
||||||
|
clock_gettime (mode, &start_time);
|
||||||
|
clock_gettime (mode, &stop_time);
|
||||||
|
long long t = (stop_time.tv_nsec - start_time.tv_nsec) +
|
||||||
|
(stop_time.tv_sec - start_time.tv_sec) * 1000000000;
|
||||||
|
printf ("%lld\n", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program...
|
||||||
|
*/
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
cpu_set_t my_set;
|
||||||
|
CPU_ZERO(&my_set);
|
||||||
|
CPU_SET(2, &my_set);
|
||||||
|
sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
|
||||||
|
|
||||||
|
printf ("clocks_per_sec=%ld\n", CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
int samples = 1000;
|
||||||
|
if (argc == 2)
|
||||||
|
samples = atol(argv[1]);
|
||||||
|
|
||||||
|
struct timespec start_time;
|
||||||
|
clock_getres (CLOCK_MONOTONIC_RAW, &start_time);
|
||||||
|
long t = start_time.tv_sec * 1000000000 + start_time.tv_nsec;
|
||||||
|
printf ("time=%ld'%03ld'%03ld ns\n", t/1000000, (t/1000)%1000, t%1000);
|
||||||
|
|
||||||
|
measure (CLOCK_MONOTONIC_RAW, samples);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
src/05-optimization/clock/meazure.xlsx
Normal file
BIN
src/05-optimization/clock/meazure.xlsx
Normal file
Binary file not shown.
89
src/05-optimization/ex01/Makefile
Normal file
89
src/05-optimization/ex01/Makefile
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
# Noms de tes deux exécutables
|
||||||
|
EXE_BASIC=basic
|
||||||
|
EXE_OPTI=optimized
|
||||||
|
|
||||||
|
# Fichiers sources pour chaque version (à adapter avec tes vrais noms de fichiers)
|
||||||
|
SRCS_BASIC=basic.c
|
||||||
|
SRCS_OPTI=optimized.c
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
# Configuration Nano
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
CFLAGS+=-fno-omit-frame-pointer
|
||||||
|
EXEC_SUFFIX=
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Configuration Host
|
||||||
|
ifeq ($(target),host)
|
||||||
|
TOOLCHAIN=
|
||||||
|
EXEC_SUFFIX=_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
|
||||||
|
# Génération des listes de fichiers objets (.o) pour chaque programme
|
||||||
|
OBJS_BASIC = $(addprefix $(OBJDIR)/, $(SRCS_BASIC:.c=.o))
|
||||||
|
OBJS_OPTI = $(addprefix $(OBJDIR)/, $(SRCS_OPTI:.c=.o))
|
||||||
|
|
||||||
|
# Noms finaux des exécutables en fonction de la cible (nano ou host)
|
||||||
|
EXEC_BASIC = $(EXE_BASIC)$(EXEC_SUFFIX)
|
||||||
|
EXEC_OPTI = $(EXE_OPTI)$(EXEC_SUFFIX)
|
||||||
|
|
||||||
|
# --- RÈGLES DE COMPILATION ---
|
||||||
|
|
||||||
|
# Règle par défaut : build les deux programmes
|
||||||
|
all: $(EXEC_BASIC) $(EXEC_OPTI)
|
||||||
|
|
||||||
|
# Règles pour build individuellement : "make basic" ou "make opti"
|
||||||
|
basic: $(EXEC_BASIC)
|
||||||
|
opti: $(EXEC_OPTI)
|
||||||
|
|
||||||
|
# Règle de compilation des .c en .o
|
||||||
|
# Le "| $(OBJDIR)" signifie que le dossier doit exister, mais que sa date de modification ne force pas la recompilation
|
||||||
|
$(OBJDIR)/%.o: %.c | $(OBJDIR)
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
# Édition de liens (Linker) pour le programme basique
|
||||||
|
$(EXEC_BASIC): $(OBJS_BASIC)
|
||||||
|
$(LD) $(OBJS_BASIC) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
# Édition de liens (Linker) pour le programme optimisé
|
||||||
|
$(EXEC_OPTI): $(OBJS_OPTI)
|
||||||
|
$(LD) $(OBJS_OPTI) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
# Création du dossier d'objets
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
# --- RÈGLES DE NETTOYAGE ET DUMP ---
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC_BASIC) $(EXEC_OPTI) *~ t_*.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE_BASIC)* $(EXE_OPTI)*
|
||||||
|
|
||||||
|
dump_basic: $(EXEC_BASIC)
|
||||||
|
$(OBJDUMP) -dS $(EXEC_BASIC) > t_basic.txt
|
||||||
|
|
||||||
|
dump_opti: $(EXEC_OPTI)
|
||||||
|
$(OBJDUMP) -dS $(EXEC_OPTI) > t_opti.txt
|
||||||
|
|
||||||
|
# Inclusion des dépendances générées par l'option -MD
|
||||||
|
-include $(OBJS_BASIC:.o=.d) $(OBJS_OPTI:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all basic opti clean clean_all dump_basic dump_opti
|
||||||
54
src/05-optimization/ex02/Makefile
Normal file
54
src/05-optimization/ex02/Makefile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
EXE=ex2
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O0 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables -fno-omit-frame-pointer
|
||||||
|
##CFLAGS+=-O2
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
24
src/05-optimization/ex02/main.c
Normal file
24
src/05-optimization/ex02/main.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define SIZE 65536
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// generate data
|
||||||
|
short data[SIZE];
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
data[i] = rand() % 512;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
long long sum = 0;
|
||||||
|
for (int j = 0; j < 10000; j++) {
|
||||||
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
if (data[i] >= 256) {
|
||||||
|
sum += data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf ("sum=%lld\n", sum);
|
||||||
|
}
|
||||||
37
src/05-optimization/ex03/ApacheAccessLogAnalyzer.cpp
Normal file
37
src/05-optimization/ex03/ApacheAccessLogAnalyzer.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "ApacheAccessLogAnalyzer.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
ApacheAccessLogAnalyzer::ApacheAccessLogAnalyzer(std::string filename)
|
||||||
|
: myFilename(filename)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApacheAccessLogAnalyzer::openFile()
|
||||||
|
{
|
||||||
|
myInFile.open(myFilename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApacheAccessLogAnalyzer::closeFile()
|
||||||
|
{
|
||||||
|
myInFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApacheAccessLogAnalyzer::processFile()
|
||||||
|
{
|
||||||
|
std::cout << "Processing log file " << myFilename << std::endl;
|
||||||
|
for( std::string line; getline( myInFile, line ); )
|
||||||
|
{
|
||||||
|
// parse the log line to extract the hostname / ip address
|
||||||
|
int space_pos = line.find_first_of(" ");
|
||||||
|
std::string hostname = line.substr(0, space_pos);
|
||||||
|
|
||||||
|
myHostCounter.notifyHost(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Found " << myHostCounter.getNbOfHosts() << " unique Hosts/IPs" << std::endl;
|
||||||
|
}
|
||||||
20
src/05-optimization/ex03/ApacheAccessLogAnalyzer.h
Normal file
20
src/05-optimization/ex03/ApacheAccessLogAnalyzer.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#include "HostCounter.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
class ApacheAccessLogAnalyzer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ApacheAccessLogAnalyzer(std::string filename);
|
||||||
|
|
||||||
|
void openFile();
|
||||||
|
void closeFile();
|
||||||
|
void processFile();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string myFilename;
|
||||||
|
std::ifstream myInFile;
|
||||||
|
HostCounter myHostCounter;
|
||||||
|
};
|
||||||
26
src/05-optimization/ex03/HostCounter.cpp
Normal file
26
src/05-optimization/ex03/HostCounter.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "HostCounter.h"
|
||||||
|
|
||||||
|
#include <algorithm> // for std::find
|
||||||
|
|
||||||
|
HostCounter::HostCounter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HostCounter::isNewHost(std::string hostname)
|
||||||
|
{
|
||||||
|
return std::find(myHosts.begin(), myHosts.end(), hostname) == myHosts.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void HostCounter::notifyHost(std::string hostname)
|
||||||
|
{
|
||||||
|
// add the host in the list if not already in
|
||||||
|
if(isNewHost(hostname))
|
||||||
|
{
|
||||||
|
myHosts.push_back(hostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int HostCounter::getNbOfHosts()
|
||||||
|
{
|
||||||
|
return myHosts.size();
|
||||||
|
}
|
||||||
22
src/05-optimization/ex03/HostCounter.h
Normal file
22
src/05-optimization/ex03/HostCounter.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class HostCounter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HostCounter();
|
||||||
|
|
||||||
|
// Announce a host to the HostCounter.
|
||||||
|
// if the host is new, it will be added to the list, otherwise we ignore it.
|
||||||
|
void notifyHost(std::string hostname);
|
||||||
|
|
||||||
|
// return the number of unique hosts found so far
|
||||||
|
int getNbOfHosts();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// check if host is already in the list
|
||||||
|
bool isNewHost(std::string hostname);
|
||||||
|
|
||||||
|
std::vector< std::string > myHosts;
|
||||||
|
};
|
||||||
30
src/05-optimization/ex03/Makefile
Normal file
30
src/05-optimization/ex03/Makefile
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
##CXX?=g++
|
||||||
|
##CXXFLAGS=-Wall -Wextra -g -O0 -MD
|
||||||
|
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CXX=$(TOOLCHAIN)g++
|
||||||
|
CXXFLAGS=-Wall -Wextra -g -gdwarf -O0 -MD -mcpu=cortex-a53 -fno-omit-frame-pointer -funwind-tables
|
||||||
|
|
||||||
|
SOURCES=$(wildcard *.cpp)
|
||||||
|
OBJECTS=$(SOURCES:.cpp=.o)
|
||||||
|
EXECUTABLE=read-apache-logs
|
||||||
|
|
||||||
|
all: $(SOURCES) $(EXECUTABLE)
|
||||||
|
|
||||||
|
$(EXECUTABLE): $(OBJECTS)
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ $(OBJECTS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CXX) -c $(CXXFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJECTS)
|
||||||
|
@rm -f *.d *~
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
@rm -f $(EXECUTABLE)
|
||||||
|
@rm -f perf.data perf.data.old
|
||||||
|
|
||||||
|
-include *.d
|
||||||
30
src/05-optimization/ex03/main.cpp
Normal file
30
src/05-optimization/ex03/main.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include "ApacheAccessLogAnalyzer.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
void usage(const char* progName);
|
||||||
|
|
||||||
|
int main(int argc, const char* argv[])
|
||||||
|
{
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
usage(argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string filename = argv[1];
|
||||||
|
|
||||||
|
ApacheAccessLogAnalyzer analyzer(filename);
|
||||||
|
|
||||||
|
analyzer.openFile();
|
||||||
|
analyzer.processFile();
|
||||||
|
analyzer.closeFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void usage(const char* progName)
|
||||||
|
{
|
||||||
|
std::cout << "Usage: " << progName << " <filename>" << std::endl;
|
||||||
|
std::cout << "\nWhere <filename> is the apache access log file" << std::endl;
|
||||||
|
}
|
||||||
34
src/05-optimization/gcov/Makefile
Normal file
34
src/05-optimization/gcov/Makefile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
CC?=gcc
|
||||||
|
CFLAGS=-std=c11 -Wall -g -fprofile-arcs -ftest-coverage
|
||||||
|
SOURCES=$(wildcard *.c)
|
||||||
|
OBJECTS=$(SOURCES:.c=.o)
|
||||||
|
EXECUTABLE=example-gcov
|
||||||
|
|
||||||
|
all: $(SOURCES) $(EXECUTABLE)
|
||||||
|
|
||||||
|
$(EXECUTABLE): $(OBJECTS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(OBJECTS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJECTS)
|
||||||
|
@rm -f *.d
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
@rm -f $(EXECUTABLE)
|
||||||
|
@rm -f perf.data perf.data.old
|
||||||
|
@rm -f *.gcno *.gcda *.gcov
|
||||||
|
|
||||||
|
|
||||||
|
gcov-generate: all
|
||||||
|
./$(EXECUTABLE)
|
||||||
|
gcov main.c
|
||||||
|
|
||||||
|
gcov-read: gcov-generate
|
||||||
|
less main.c.gcov
|
||||||
|
|
||||||
|
|
||||||
|
-include *.d
|
||||||
19
src/05-optimization/gcov/main.c
Normal file
19
src/05-optimization/gcov/main.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int res = 1;
|
||||||
|
for (int i=0; i<16; i++)
|
||||||
|
{
|
||||||
|
res *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(res < 10)
|
||||||
|
{
|
||||||
|
printf("dead code\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("res=%d\n", res);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
54
src/05-optimization/gpio/Makefile
Normal file
54
src/05-optimization/gpio/Makefile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
EXE=gpio
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
87
src/05-optimization/gpio/gpio.c
Normal file
87
src/05-optimization/gpio/gpio.c
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define GPIO_EXPORT "/sys/class/gpio/export"
|
||||||
|
#define GPIO_UNEXPORT "/sys/class/gpio/unexport"
|
||||||
|
#define GPIO_GPIOG11 "/sys/class/gpio/gpio203"
|
||||||
|
#define GPIOG11 "203"
|
||||||
|
|
||||||
|
static int open_gpio()
|
||||||
|
{
|
||||||
|
// unexport pin out of sysfs (reinitialization)
|
||||||
|
int f = open (GPIO_UNEXPORT, O_WRONLY);
|
||||||
|
write (f, GPIOG11, strlen(GPIOG11));
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// export pin to sysfs
|
||||||
|
f = open (GPIO_EXPORT, O_WRONLY);
|
||||||
|
write (f, GPIOG11, strlen(GPIOG11));
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// config pin
|
||||||
|
f = open (GPIO_GPIOG11 "/direction", O_WRONLY);
|
||||||
|
write (f, "out", 3);
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// open gpio value attribute
|
||||||
|
f = open (GPIO_GPIOG11 "/value", O_RDWR);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program...
|
||||||
|
*/
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cpu_set_t my_set;
|
||||||
|
CPU_ZERO(&my_set);
|
||||||
|
CPU_SET(2, &my_set);
|
||||||
|
sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
|
||||||
|
|
||||||
|
int gpio = open_gpio();
|
||||||
|
bool on = false;
|
||||||
|
struct timespec start_time;
|
||||||
|
struct timespec stop_time;
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &start_time); // setup...
|
||||||
|
|
||||||
|
|
||||||
|
// --> measurement with internal timers
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &start_time);
|
||||||
|
for (int i=0; i<1000; i++) {
|
||||||
|
if (on) {
|
||||||
|
pwrite (gpio, "1", sizeof("1"), 0);
|
||||||
|
} else {
|
||||||
|
pwrite (gpio, "0", sizeof("0"), 0);
|
||||||
|
}
|
||||||
|
on = !on;
|
||||||
|
}
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &stop_time);
|
||||||
|
long long t = (stop_time.tv_nsec - start_time.tv_nsec) +
|
||||||
|
(stop_time.tv_sec - start_time.tv_sec) * 1000000000;
|
||||||
|
printf ("pwrite (gpio, \"1\", sizeof(\"1\"), 0) -> %lld ns\n", t/1000);
|
||||||
|
|
||||||
|
|
||||||
|
// --> measurement with oscilloscope
|
||||||
|
while(true) {
|
||||||
|
if (on) {
|
||||||
|
pwrite (gpio, "1", sizeof("1"), 0);
|
||||||
|
} else {
|
||||||
|
pwrite (gpio, "0", sizeof("0"), 0);
|
||||||
|
}
|
||||||
|
on = !on;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
34
src/05-optimization/gprof/Makefile
Normal file
34
src/05-optimization/gprof/Makefile
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
CC?=gcc
|
||||||
|
CFLAGS=-std=c11 -Wall -pg
|
||||||
|
SOURCES=$(wildcard *.c)
|
||||||
|
OBJECTS=$(SOURCES:.c=.o)
|
||||||
|
EXECUTABLE=example-gprof
|
||||||
|
|
||||||
|
all: $(SOURCES) $(EXECUTABLE)
|
||||||
|
|
||||||
|
$(EXECUTABLE): $(OBJECTS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(OBJECTS)
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJECTS)
|
||||||
|
@rm -f *.d
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
@rm -f $(EXECUTABLE)
|
||||||
|
@rm -f perf.data perf.data.old
|
||||||
|
@rm -f gmon.out gprof.out
|
||||||
|
|
||||||
|
|
||||||
|
gprof-generate: all
|
||||||
|
./$(EXECUTABLE)
|
||||||
|
gprof $(EXECUTABLE) > gprof.out
|
||||||
|
|
||||||
|
gprof-read:
|
||||||
|
less gprof.out
|
||||||
|
|
||||||
|
|
||||||
|
-include *.d
|
||||||
21
src/05-optimization/gprof/main.c
Normal file
21
src/05-optimization/gprof/main.c
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
void func1(void)
|
||||||
|
{
|
||||||
|
for(int i=0; i<0xfffffff; i++); // wait...
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void func2(void)
|
||||||
|
{
|
||||||
|
for(int i=0;i<0xfffffff;i++); // wait...
|
||||||
|
func1();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
for(int i=0;i<0xfffffff;i++);
|
||||||
|
func1();
|
||||||
|
func2();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
71
src/05-optimization/gprof/target.mk
Normal file
71
src/05-optimization/gprof/target.mk
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
EXE=example-gprof
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE -pg
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),xu3)
|
||||||
|
TOOLCHAIN_PATH=~/workspace/xu3/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)arm-linux-gnueabihf-
|
||||||
|
CFLAGS+=-mcpu=cortex-a15.cortex-a7 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/xu3
|
||||||
|
EXEC=$(EXE)_a
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
@rm -f perf.data perf.data.old gmon.out gprof.out
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
gprof-generate: all
|
||||||
|
./$(EXECUTABLE)
|
||||||
|
gprof $(EXECUTABLE) > gprof.out
|
||||||
|
|
||||||
|
gprof-read:
|
||||||
|
less gprof.out
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
54
src/05-optimization/mmio/Makefile
Normal file
54
src/05-optimization/mmio/Makefile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
EXE=mmio
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
98
src/05-optimization/mmio/mmio.c
Normal file
98
src/05-optimization/mmio/mmio.c
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define GPIO_EXPORT "/sys/class/gpio/export"
|
||||||
|
#define GPIO_UNEXPORT "/sys/class/gpio/unexport"
|
||||||
|
#define GPIO_GPIOG11 "/sys/class/gpio/gpio203"
|
||||||
|
#define GPIOG11 "203"
|
||||||
|
|
||||||
|
static int open_gpio()
|
||||||
|
{
|
||||||
|
// unexport pin out of sysfs (reinitialization)
|
||||||
|
int f = open (GPIO_UNEXPORT, O_WRONLY);
|
||||||
|
write (f, GPIOG11, strlen(GPIOG11));
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// export pin to sysfs
|
||||||
|
f = open (GPIO_EXPORT, O_WRONLY);
|
||||||
|
write (f, GPIOG11, strlen(GPIOG11));
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// config pin
|
||||||
|
f = open (GPIO_GPIOG11 "/direction", O_WRONLY);
|
||||||
|
write (f, "out", 3);
|
||||||
|
close (f);
|
||||||
|
|
||||||
|
// open gpio value attribute
|
||||||
|
f = open (GPIO_GPIOG11 "/value", O_RDWR);
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main program...
|
||||||
|
*/
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cpu_set_t my_set;
|
||||||
|
CPU_ZERO(&my_set);
|
||||||
|
CPU_SET(2, &my_set);
|
||||||
|
sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
|
||||||
|
|
||||||
|
int gpio = open_gpio();
|
||||||
|
pwrite (gpio, "1", sizeof("1"), 0);
|
||||||
|
pwrite (gpio, "0", sizeof("0"), 0);
|
||||||
|
|
||||||
|
int fd = open ("/dev/mem", O_RDWR);
|
||||||
|
if (fd == -1) return -1;
|
||||||
|
off_t psz = getpagesize();
|
||||||
|
volatile uint32_t* pio = mmap (0, psz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x01c20000);
|
||||||
|
volatile uint32_t* dat_pio = pio + (0x810+6*0x24)/4;
|
||||||
|
|
||||||
|
struct timespec start_time;
|
||||||
|
struct timespec stop_time;
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &start_time); // setup...
|
||||||
|
|
||||||
|
// --> measurement with internal timers on gpio
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &start_time);
|
||||||
|
|
||||||
|
for (int i=0; i<1000; i++)
|
||||||
|
*dat_pio ^= (1<<11);
|
||||||
|
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &stop_time);
|
||||||
|
long long t = (stop_time.tv_nsec - start_time.tv_nsec) +
|
||||||
|
(stop_time.tv_sec - start_time.tv_sec) * 1000000000;
|
||||||
|
printf ("*dat_pio ^= (1<<11) --> %6lld ns\n", t/1000);
|
||||||
|
|
||||||
|
|
||||||
|
// --> measurement on internal data with internal timers
|
||||||
|
volatile uint32_t data = 0;
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &start_time);
|
||||||
|
|
||||||
|
for (int i=0; i<1000; i++)
|
||||||
|
data ^= (1<<11);
|
||||||
|
|
||||||
|
clock_gettime (CLOCK_MONOTONIC, &stop_time);
|
||||||
|
t = (stop_time.tv_nsec - start_time.tv_nsec) +
|
||||||
|
(stop_time.tv_sec - start_time.tv_sec) * 1000000000;
|
||||||
|
printf ("data ^= (1<<11) --> %6lld ns\n", t/1000);
|
||||||
|
|
||||||
|
|
||||||
|
// --> measurement with oscilloscope
|
||||||
|
while(true) {
|
||||||
|
*dat_pio ^= (1<<11);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
54
src/05-optimization/trace/Makefile
Normal file
54
src/05-optimization/trace/Makefile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
EXE=tracing
|
||||||
|
SRCS=$(wildcard *.c)
|
||||||
|
|
||||||
|
ifeq ($(target),)
|
||||||
|
target=nano
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE
|
||||||
|
|
||||||
|
ifeq ($(target),nano)
|
||||||
|
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||||
|
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||||
|
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||||
|
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||||
|
OBJDIR=.obj/nano
|
||||||
|
EXEC=$(EXE)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(target),host)
|
||||||
|
EXEC=$(EXE)_h
|
||||||
|
endif
|
||||||
|
|
||||||
|
CC=$(TOOLCHAIN)gcc
|
||||||
|
LD=$(TOOLCHAIN)gcc
|
||||||
|
AR=$(TOOLCHAIN)ar
|
||||||
|
STRIP=$(TOOLCHAIN)strip
|
||||||
|
OBJDUMP=$(TOOLCHAIN)objdump
|
||||||
|
|
||||||
|
OBJDIR=.obj/$(target)
|
||||||
|
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
$(OBJDIR)/%o: %c
|
||||||
|
$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: $(OBJDIR)/ $(EXEC)
|
||||||
|
|
||||||
|
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||||
|
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
$(OBJDIR)/:
|
||||||
|
mkdir -p $(OBJDIR)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||||
|
|
||||||
|
clean_all: clean
|
||||||
|
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||||
|
|
||||||
|
dump: all
|
||||||
|
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||||
|
|
||||||
|
-include $(OBJS:.o=.d)
|
||||||
|
|
||||||
|
.PHONY: all clean clean_all dump
|
||||||
7
src/05-optimization/trace/example1.sh
Normal file
7
src/05-optimization/trace/example1.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# 1. example
|
||||||
|
echo 1 > /sys/kernel/debug/tracing/events/sched/sched_switch/enable
|
||||||
|
./tracing &
|
||||||
|
pidof tracing > /sys/kernel/debug/tracing/set_event_pid
|
||||||
|
echo 1 > /sys/kernel/debug/tracing/tracing_on ; sleep 2 ; echo 0 > /sys/kernel/debug/tracing/tracing_on
|
||||||
|
trace-cmd show
|
||||||
10
src/05-optimization/trace/example2.sh
Normal file
10
src/05-optimization/trace/example2.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# 2. example
|
||||||
|
echo function_graph > /sys/kernel/debug/tracing/current_tracer
|
||||||
|
echo *i2c* > /sys/kernel/debug/tracing/set_ftrace_filter
|
||||||
|
echo 1 > /sys/kernel/debug/tracing/tracing_on
|
||||||
|
i2cdetect -y 0
|
||||||
|
echo 0 > /sys/kernel/debug/tracing/tracing_on
|
||||||
|
trace-cmd show
|
||||||
|
echo nop > /sys/kernel/debug/tracing/current_tracer
|
||||||
|
|
||||||
8
src/05-optimization/trace/main.c
Normal file
8
src/05-optimization/trace/main.c
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
while(1)
|
||||||
|
sleep(1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
src/05-optimization/trace/setup.sh
Normal file
1
src/05-optimization/trace/setup.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
mount -t debugfs nodev /sys/kernel/debug
|
||||||
Reference in New Issue
Block a user