본문 바로가기

분류 전체보기

(695)
최대공약수, 최소공배수 두 수의 최대공약수를 구하는 알고리즘은 유클리드 호제법을 베이스로 한다. 78696 = 19332×4 + 1368 19332 = 1368×14 + 180 1368 = 180×7 + 108 180 = 108×1 + 72 108 = 72×1 + 36 72 = 36×2 gcd = 36 출처 https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95 큰 수(a)에서 작은 수(b)로 나누어 그 나머지(r)가 존재하면 작은 수에서 그 나머지로 나누는 과정을 나머지가 없을 때 까지 재귀적으로 반복하는 것이다. int gcd(int a, int b) // always a > b { // int remainde..
가변인자 템플릿 #include #include template void print(T arg) { // 마지막 가변인자를 받게 됨. std::cout
std::filesystem visual studio 에서 std::filesystem 사용을 위해선 다음과 같은 설정이 필요하다. #include #include int main() { const auto print_value = [](auto v) { std::cout
std::shared_ptr #include #include class A { public: int n; A(int n) { this->n = n; std::cout
std::unique_ptr #include #include class A { public: A() { std::cout
std::find() #include #include #include int main() { std::vector vec = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector sub = { 3, 4, 5 }; std::vector sub1 = { 1 ,2, 3, 3, 4, 5 }; auto itr = std::find(vec.begin(), vec.end(), 3); std::cout
nvme 디바이스 레이어에서 read/write 연산 횟수 계산 방법 struct nvme_queue { ... //int ssize; int szs[2]; //READ: 0, WRITE: 1 int ops[1024]; //sq의 depth에 맞게 설정. 포인터로 선언해서 동적할당하기를 권장 }; static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { ... if (nvmeq->qid > 0) //io를 위한 sq에 대해서, { nvmeq->ops[nvmeq->sq_tail] = rq_data_dir(req); nvmeq->szs[rq_data_dir(req)] += 1; printk("log, qid: %d, read: %d, write: %d, t..
Limited sq entry implementation struct blk_mq_alloc_data { /* input parameter */ struct request_queue *q; unsigned int flags; unsigned int shallow_depth; /* input & output parameter */ struct blk_mq_ctx *ctx; struct blk_mq_hw_ctx *hctx; unsigned int op; //read, write 확인을 위해 }; struct blk_mq_tags { unsigned int nr_tags; unsigned int nr_reserved_tags; atomic_t active_queues; struct sbitmap_queue bitmap_tags; struct sbitmap_queue..
NVMe device driver code tuning & comments - 5 작성한 커널 코드를 정리하던 중에 디버깅용으로 작성한 코드 중 SQ의 쌓인 entry 개수를 측정하는 함수가 있었다. 여기서는 이와 관련된 것을 정리하겠다. SQ의 entry가 증가하는 경우는 __nvme_submit_cmd()와 __nvme_submit_cmd_extra()를 참조하면 된다. 해당 함수에서 size를 1 증가시키는 코드의 주석을 해제하면 된다. static void __nvme_submit_cmd(struct nvme_queue *nvmeq, struct nvme_command *cmd) { u16 tail = nvmeq->sq_tail; if (nvmeq->sq_cmds_io) memcpy_toio(&nvmeq->sq_cmds_io[tail], cmd, sizeof(*cmd)); el..
NVMe device driver code tuning & comments - 4 디바이스 드라이버 초기화에 이어서, 이번에는 IO를 각 SQ에 어떻게 큐잉하는지에 대한 내용이다. 파일 시스템부터 디바이스 드라이버 계층 까지의 코드 흐름은 일단 생략하고, nvme_queue_rq() 함수에 대해 소개하겠다. 이 함수에 대해 간단히 설명하면 블록 멀티 큐에서 nvme device driver 로 넘어갈 때 호출되는 함수이다. 그래서 IO type에 따라 알맞는 SQ로 큐잉하기 위해 다음과 같이 함수 일부를 수정하였다. static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { ... op = rq_data_dir(req); if (nvmeq->qid == 0) __nv..