Compare commits
No commits in common. "a64d55a819fa39752c8a6eb821e704139b8a7151" and "9a78f98540d41b216f261e60839d176a4c36f6c0" have entirely different histories.
a64d55a819
...
9a78f98540
3
Makefile
3
Makefile
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
ifneq ($(KERNELRELEASE),)
|
ifneq ($(KERNELRELEASE),)
|
||||||
# kbuild part of makefile
|
# kbuild part of makefile
|
||||||
obj-m := hello1.o hello2.o
|
obj-m := hello.o
|
||||||
ccflags-y := -I$(obj)/inc
|
|
||||||
else
|
else
|
||||||
# normal makefile
|
# normal makefile
|
||||||
KDIR ?= /lib/modules/`uname -r`/build
|
KDIR ?= /lib/modules/`uname -r`/build
|
||||||
|
|
|
@ -40,54 +40,48 @@ MODULE_LICENSE("Dual BSD/GPL");
|
||||||
|
|
||||||
struct TimingList {
|
struct TimingList {
|
||||||
struct TimingList *next;
|
struct TimingList *next;
|
||||||
ktime_t t_before;
|
ktime_t t;
|
||||||
ktime_t t_after;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int msg_count = 1;
|
static unsigned int msg_count = 1;
|
||||||
static struct TimingList *tl_head;
|
static struct TimingList *tl_head;
|
||||||
|
|
||||||
static struct TimingList* write_first_node(void)
|
static void init_new_list(void)
|
||||||
{
|
{
|
||||||
tl_head = kmalloc(sizeof(struct TimingList), GFP_KERNEL);
|
tl_head = kmalloc(sizeof(struct TimingList), GFP_KERNEL);
|
||||||
tl_head->next = NULL;
|
|
||||||
|
|
||||||
return tl_head;
|
tl_head->next = NULL;
|
||||||
|
tl_head->t = ktime_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct TimingList* insert_next_node(struct TimingList *tail)
|
static void insert_new_time(void)
|
||||||
{
|
{
|
||||||
|
struct TimingList *last_tl_node = tl_head;
|
||||||
struct TimingList *new_tl_node = kmalloc(sizeof(struct TimingList),
|
struct TimingList *new_tl_node = kmalloc(sizeof(struct TimingList),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
|
||||||
tail->next = new_tl_node;
|
while (last_tl_node->next != NULL)
|
||||||
|
last_tl_node = last_tl_node->next;
|
||||||
|
|
||||||
|
|
||||||
new_tl_node->next = NULL;
|
new_tl_node->next = NULL;
|
||||||
|
new_tl_node->t = ktime_get();
|
||||||
|
|
||||||
return new_tl_node;
|
last_tl_node->next = new_tl_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct TimingList* add_new_node(struct TimingList *tail)
|
static void print_time(ktime_t *t)
|
||||||
{
|
{
|
||||||
if (tail == NULL)
|
printk(KERN_EMERG "%lld\n", *t);
|
||||||
return write_first_node();
|
|
||||||
else
|
|
||||||
return insert_next_node(tail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_time_diff(struct TimingList *node)
|
static void destroy_list(void)
|
||||||
{
|
|
||||||
pr_info("%lld\n", node->t_after - node->t_before);
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_list(void)
|
|
||||||
{
|
{
|
||||||
struct TimingList *curr_tl = tl_head;
|
struct TimingList *curr_tl = tl_head;
|
||||||
struct TimingList *next_tl = NULL;
|
struct TimingList *next_tl = NULL;
|
||||||
|
|
||||||
tl_head = NULL;
|
|
||||||
|
|
||||||
while (curr_tl != NULL) {
|
while (curr_tl != NULL) {
|
||||||
print_time_diff(curr_tl);
|
print_time(&(curr_tl->t));
|
||||||
|
|
||||||
next_tl = curr_tl->next;
|
next_tl = curr_tl->next;
|
||||||
kfree(curr_tl);
|
kfree(curr_tl);
|
||||||
|
@ -95,34 +89,38 @@ void destroy_list(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void update_timing_list(void)
|
||||||
|
{
|
||||||
|
if (tl_head == NULL)
|
||||||
|
init_new_list();
|
||||||
|
else
|
||||||
|
insert_new_time();
|
||||||
|
}
|
||||||
|
|
||||||
static int __init hello_init(void)
|
static int __init hello_init(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
if (msg_count > 10) {
|
if (msg_count > 10) {
|
||||||
pr_err("Error: msg_count too large (%d > 10)\n", msg_count);
|
printk(KERN_EMERG "Error: msg_count too large (%d > 10)\n",
|
||||||
|
msg_count);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg_count == 0 || msg_count >= 5) {
|
if (msg_count == 0 || msg_count >= 5) {
|
||||||
pr_warn("Warning: msg_count = %d (msg_count == 0 or 5 <= msg_count <= 10)\n", msg_count);
|
printk(KERN_EMERG "Warning: msg_count = %d (msg_count == 0 or 5 <= msg_count <= 10)\n",
|
||||||
|
msg_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < msg_count; i++) {
|
||||||
|
update_timing_list();
|
||||||
|
|
||||||
|
printk(KERN_EMERG "Hello, world!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_hello(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct TimingList *current_tail = tl_head;
|
|
||||||
|
|
||||||
for (i = 0; i < msg_count; i++) {
|
|
||||||
current_tail = add_new_node(current_tail);
|
|
||||||
|
|
||||||
current_tail->t_before = ktime_get();
|
|
||||||
pr_info("Hello, world!\n");
|
|
||||||
current_tail->t_after = ktime_get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __exit hello_exit(void)
|
static void __exit hello_exit(void)
|
||||||
{
|
{
|
||||||
destroy_list();
|
destroy_list();
|
||||||
|
@ -131,8 +129,5 @@ static void __exit hello_exit(void)
|
||||||
module_param(msg_count, uint, 0444);
|
module_param(msg_count, uint, 0444);
|
||||||
MODULE_PARM_DESC(msg_count, "Amount of hello world outputs on load");
|
MODULE_PARM_DESC(msg_count, "Amount of hello world outputs on load");
|
||||||
|
|
||||||
EXPORT_SYMBOL(print_hello);
|
|
||||||
EXPORT_SYMBOL(destroy_list);
|
|
||||||
|
|
||||||
module_init(hello_init);
|
module_init(hello_init);
|
||||||
module_exit(hello_exit);
|
module_exit(hello_exit);
|
55
hello2.c
55
hello2.c
|
@ -1,55 +0,0 @@
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2017, GlobalLogic Ukraine LLC
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* 1. Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by the GlobalLogic.
|
|
||||||
* 4. Neither the name of the GlobalLogic nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY GLOBALLOGIC UKRAINE LLC ``AS IS`` AND ANY
|
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL GLOBALLOGIC UKRAINE LLC BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/printk.h>
|
|
||||||
#include <linux/slab.h>
|
|
||||||
|
|
||||||
#include "hello1.h"
|
|
||||||
|
|
||||||
MODULE_AUTHOR("Serhii Popovych <serhii.popovych@globallogic.com>");
|
|
||||||
MODULE_DESCRIPTION("Hello, world in Linux Kernel Training");
|
|
||||||
MODULE_LICENSE("Dual BSD/GPL");
|
|
||||||
|
|
||||||
static int __init hello_init(void)
|
|
||||||
{
|
|
||||||
print_hello();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __exit hello_exit(void)
|
|
||||||
{
|
|
||||||
destroy_list();
|
|
||||||
}
|
|
||||||
|
|
||||||
module_init(hello_init);
|
|
||||||
module_exit(hello_exit);
|
|
|
@ -1,2 +0,0 @@
|
||||||
void print_hello(void);
|
|
||||||
void destroy_list(void);
|
|
Loading…
Reference in New Issue