Linux API/linux2018. 4. 17. 14:39

odroid에서 가버너 정책에 따라 cpu 갯수와 속도가 달라져서

어떤식으로 구현되는지 한번 찾아보는 중


해당 내용은 linux kernel 의 device driver 부분에 구현되어있다.(drivers/cpufreq/) 


## drivers/cpufreq/cpufreq_hotplug.c

해당 파일은 크게 두부분으로 나뉘어있다. sysfs 를 구성하는 파일에 대한 내용을 구현한 부분과 governor 의 hotplug 정책에 맞게 cpu load를 계산해서 cpu 를 끄고 켜는 부분이다. 

[링크 : http://pinocc.tistory.com/47]

[링크 : https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt]

[링크 : http://blog.dasomoli.org/472/] 위에꺼 번역?


[링크 : http://com.odroid.com/sigong/nf_board/nboard_view.php?brd_id=odroidc2&bid=7596]


+

cpu_up()

cpu_disable()


[링크 : https://android.googlesource.com/.../android-mediatek-sprout-3.4-kitkat-mr2/drivers/cpufreq]

[링크 : https://www.kernel.org/doc/html/v4.13/core-api/cpu_hotplug.html]

[링크 : https://www.kernel.org/doc/ols/2004/ols2004v2-pages-181-194.pdf]



+

[링크 : https://github.com/hardkernel/linux/blob/odroid-3.8.y/drivers/cpufreq/exynos4x12-cpufreq.c]

[링크 : https://github.com/hardkernel/linux/blob/odroid-3.8.y/drivers/cpufreq/exynos4x12-dvfs-hotplug.c]

'Linux API > linux' 카테고리의 다른 글

ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
전원버튼 IRQ 발생 관련  (0) 2018.04.23
linux shared memory 관련  (0) 2016.12.22
linux ipc  (0) 2016.12.20
pthread detach while  (0) 2016.12.20
Posted by 구차니
Linux API/linux2016. 12. 22. 14:41
shm으로 시작하는걸 찾으니 아래와 같이 나오는데

shm_open같은 shm_으로 시작하는 애들은 정체가...

POSIX 관련인가.. shm은 리눅스 쪽?

$ man -k shm

shm_open (3)         - Create/open or unlink POSIX shared memory objects

shm_overview (7)     - Overview of POSIX shared memory

shm_unlink (3)       - Create/open or unlink POSIX shared memory objects

shmat (2)            - shared memory operations

shmctl (2)           - shared memory control

shmdt (2)            - shared memory operations

shmget (2)           - allocates a shared memory segment

shmop (2)            - shared memory operations 


#include <sys/ipc.h>

#include <sys/shm.h>


int shmget(key_t key, size_t size, int shmflg);

shmflg = IPC_CREAT | IPC_EXCL;


void *shmat(int shmid, const void *shmaddr, int shmflg);

int shmdt(const void *shmaddr);


int shmctl(int shmid, int cmd, struct shmid_ds *buf);


#include <sys/types.h>

#include <sys/shm.h>


void *shmat(int shmid, const void *shmaddr, int shmflg);

int shmdt(const void *shmaddr);


다시 보니.. shm은 SystemV 계열

shm_ 은 POSIX 계열 인듯?

[링크 : http://stackoverflow.com/questions/4582968/system-v-ipc-vs-posix-ipc]

'Linux API > linux' 카테고리의 다른 글

전원버튼 IRQ 발생 관련  (0) 2018.04.23
linux kernel governor 관련 코드  (0) 2018.04.17
linux ipc  (0) 2016.12.20
pthread detach while  (0) 2016.12.20
fd <-> fp 변환  (0) 2016.10.07
Posted by 구차니
Linux API/linux2016. 12. 20. 21:10

머라도 하나씩 직접해보자 ㅜㅜ


[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch08_IPC]

'Linux API > linux' 카테고리의 다른 글

linux kernel governor 관련 코드  (0) 2018.04.17
linux shared memory 관련  (0) 2016.12.22
pthread detach while  (0) 2016.12.20
fd <-> fp 변환  (0) 2016.10.07
shared memory - linux/IPC  (0) 2016.06.28
Posted by 구차니
Linux API/linux2016. 12. 20. 20:58

쓰레드 보다보니

공부는 해냐하는데 끄응 ㅜㅜ


암튼 쓰레드를 분리하면 자식 스레드가 종료시 자원을 반납하지만

분리할 쓰레드가 무한루프 돌면

메모리 누수로 이어지는 듯


프로세스는 종료되었고 그럼 프로세스로서 cpu를 할당받진 않을테나

해당 쓰레드가 공유하던 메모리만 붕 떠버리려나?


[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch07_Thread]

[링크 : http://stackoverflow.com/.../how-can-i-kill-a-pthread-that-is-in-an-infinite-loop-from-outside-that-loop]

[링크 : http://stackoverflow.com/questions/25655706/how-to-terminate-or-stop-a-detached-thread-in-c]

'Linux API > linux' 카테고리의 다른 글

linux shared memory 관련  (0) 2016.12.22
linux ipc  (0) 2016.12.20
fd <-> fp 변환  (0) 2016.10.07
shared memory - linux/IPC  (0) 2016.06.28
메시지 큐 - ipc  (0) 2016.06.28
Posted by 구차니
Linux API/linux2016. 10. 7. 16:59

int fileno(FILE *stream);

FILE *fdopen(int fd, const char *mode);


[링크 : http://stackoverflow.com/.../how-can-i-convert-a-file-pointer-file-fp-to-a-file-descriptor-int-fd]

[링크 : http://stackoverflow.com/.../how-to-get-a-file-pointer-from-a-file-descriptor]

[링크 : https://linux.die.net/man/3/fileno]

[링크 : https://linux.die.net/man/3/fdopen]

'Linux API > linux' 카테고리의 다른 글

linux ipc  (0) 2016.12.20
pthread detach while  (0) 2016.12.20
shared memory - linux/IPC  (0) 2016.06.28
메시지 큐 - ipc  (0) 2016.06.28
pthread mutex shm_open  (0) 2016.06.27
Posted by 구차니
Linux API/linux2016. 6. 28. 15:56

System V와 POSIX 차이

[링크 : http://stackcanary.com/?p=59]


System V

[링크 : http://linux.die.net/man/2/shmget]

[링크 : http://linux.die.net/man/2/shmat] attach

[링크 : http://linux.die.net/man/2/shmdt] detach

[링크 : http://linux.die.net/man/2/shmctl]


POSIX


System V shared memory (shmget(2), shmop(2), etc.) is an older shared memory API. POSIX shared memory provides a simpler, and better designed interface; on the other hand POSIX shared memory is somewhat less widely available (especially on older systems) than System V shared memory.

[링크 : http://linux.die.net/man/7/shm_overview]

    [링크 : http://linux.die.net/man/3/shm_open]

    [링크 : http://linux.die.net/man/2/ftruncate]

    [링크 : http://linux.die.net/man/2/mmap]

'Linux API > linux' 카테고리의 다른 글

pthread detach while  (0) 2016.12.20
fd <-> fp 변환  (0) 2016.10.07
메시지 큐 - ipc  (0) 2016.06.28
pthread mutex shm_open  (0) 2016.06.27
리눅스 동적 라이브러리(*.so) 사용하기  (0) 2016.04.04
Posted by 구차니
Linux API/linux2016. 6. 28. 15:31


#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/msg.h>


struct msgbuf {

    long mtype;       /* message type, must be > 0 */

    char mtext[1];    /* message data */

};


int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);

ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);

int msgget(key_t key, int msgflg);

[링크 : http://linux.die.net/man/2/msgsnd]

[링크 : http://linux.die.net/man/2/msgget]



[링크 : http://www.joinc.co.kr/w/Site/system_programing/Book_LSP/ch08_IPC]

[링크 : http://www.joinc.co.kr/w/Site/system_programing/IPC/MessageQueue]

'Linux API > linux' 카테고리의 다른 글

fd <-> fp 변환  (0) 2016.10.07
shared memory - linux/IPC  (0) 2016.06.28
pthread mutex shm_open  (0) 2016.06.27
리눅스 동적 라이브러리(*.so) 사용하기  (0) 2016.04.04
리눅스 커널 모듈 관련 문서  (0) 2015.11.06
Posted by 구차니
Linux API/linux2016. 6. 27. 20:51

pthread_mutexattr_destroy, pthread_mutexattr_init - destroy and initialize the mutex attributes object

[링크 : http://linux.die.net/man/3/pthread_mutexattr_init]


mutex 속성을 설정하여 프로세스간 mutex로도 사용이 가능

ret = pthread_mutexattr_setpshared(&mtx_attr, PTHREAD_PROCESS_SHARED);

[링크 : https://kldp.org/node/107186]

[링크 : http://stackoverflow.com/questions/4252005/what-is-the-attribute-of-a-pthread-mutex]


[링크 : http://mintnlatte.tistory.com/357] mmap


결론은.. 공유 메모리를 통해 mutex 키를 공유하여

다른 프로세스들과도 mutex가 가능하다?

'Linux API > linux' 카테고리의 다른 글

shared memory - linux/IPC  (0) 2016.06.28
메시지 큐 - ipc  (0) 2016.06.28
리눅스 동적 라이브러리(*.so) 사용하기  (0) 2016.04.04
리눅스 커널 모듈 관련 문서  (0) 2015.11.06
readl(), writel()  (0) 2015.11.06
Posted by 구차니
Linux API/linux2016. 4. 4. 09:21

어떻게 보면 당연한..(?)

함수 포인터


#include <stdio.h>

#include <dlfcn.h>

#include "ctest.h"


int main(int argc, char **argv) 

{

   void *lib_handle;

   double (*fn)(int *);

   int x;

   char *error;


   lib_handle = dlopen("/opt/lib/libctest.so", RTLD_LAZY);

   if (!lib_handle) 

   {

      fprintf(stderr, "%s\n", dlerror());

      exit(1);

   }


   fn = dlsym(lib_handle, "ctest1");

   if ((error = dlerror()) != NULL)  

   {

      fprintf(stderr, "%s\n", error);

      exit(1);

   }


   (*fn)(&x);

   printf("Valx=%d\n",x);


   dlclose(lib_handle);

   return 0;

[링크 : http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html]


[링크 : http://linux.die.net/man/3/dlopen]

[링크 : http://linux.die.net/man/3/dlsym]

'Linux API > linux' 카테고리의 다른 글

메시지 큐 - ipc  (0) 2016.06.28
pthread mutex shm_open  (0) 2016.06.27
리눅스 커널 모듈 관련 문서  (0) 2015.11.06
readl(), writel()  (0) 2015.11.06
리눅스 모듈 프로그래밍 관련  (0) 2015.10.30
Posted by 구차니
Linux API/linux2015. 11. 6. 11:17

kmalloc() <-> kfree()


빌드 옵션

 -c: 커널 모듈은 독립적으로 실행 가능한 파일이 아니며, insmod를 사용하여 실행 시간 중에 커널에 링크되는 오브젝트 파일 이다. 결론적으로 모듈은 -c옵션을 주고 컴파일 해야 한다. 


-O2: 커널은 인라인 함수를 주로 사용하기 때문에 모듈은 이 옵션 플래그를 사용해야 한다. 이 옵션을 사용하지 않은 경우 어떤 어셈블러 매크로는 함수 호출 시 정상적으로 작동하지 않을 것이다. insmod는 커널에서 원하는 함수를 찾지 못하고 결국 모듈의 적재는 실패할 것이다. 


-W -Wall: 프로그램에서의 실수는 당신의 시스템을 다운 시킬 수도 있다. 컴파일러 경고 기능은 항상 켜둬라, 이것은 모듈 컴파일 뿐 아니라 당신의 모든 컴파일 행위에 적용된다. 


-isystem /lib/modules/uname -r/build/include: 컴파일 대상이 되는 커널의 헤더를 사용해야만 한다. 기본적인 /usr/include/linux를 사용하는 것은 작동하지 않을 것이다. 


-DKERNEL:이 심볼을 정의 하는 것은 헤더 파일에 이 코드가 유저 프로세스로 동작하지 않고 커널 모드에서 작동한다는 사실을 알린다. 


-DMODULE: 이 심볼은 헤더 파일에 커널 모듈을 위한 올바른 정의를 하게 한다. 


이름을 정해준대로 쓰거나

int init_module(void);

void cleanup_module(void); 


module_init / module_exit 매크로를 통해 연결해 주거나
int hello_2_init(void);
static void hello_2_exit(void);
module_init(hello_2_init);
module_exit(hello_2_exit);


표준 라이브러리는 사용할 수 없다. 당신이 커널 모듈에서 사용 할 수 있는 함수는 /proc/ksyms에서 보이는 함수들 뿐이다. 

[링크 : https://wiki.kldp.org/wiki.php/KernelModuleProgrammingGuide]


/proc/ksyms 가 2.6 에서는 /proc/kallsyms 로 바뀌었습니다.

[링크 : https://kldp.org/node/27882]


커널에서 FP 쪽은 데이터 주고 받는 용도로 써서 floating point 연산불가

math 라이브러리도 사용불가 -_-

[링크 : http://stackoverflow.com/.../how-to-include-math-h-include-math-h-on-kernel-source-file]


[링크 : http://hisjournal.net/./The_Linux_Kernel_Module_Programming_Guide_v2.6_by_YoonMin_Nam.pdf]

[링크 : http://www.joinc.co.kr/.../system_programing/proc/ProcFsPrograming] proc fs

'Linux API > linux' 카테고리의 다른 글

pthread mutex shm_open  (0) 2016.06.27
리눅스 동적 라이브러리(*.so) 사용하기  (0) 2016.04.04
readl(), writel()  (0) 2015.11.06
리눅스 모듈 프로그래밍 관련  (0) 2015.10.30
linux open mode  (0) 2015.10.29
Posted by 구차니