lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Some Linux Kernel codes

Tue Oct 07, 2014 3:02 am

1)

Code: Select all

	rtnl_link_register(&batadv_link_ops);
what does rtnl_link_register really does? what does rtnl stands for?

2)

Code: Select all

INIT_HLIST_HEAD(&bat_priv->gw.list);
    INIT_LIST_HEAD(&bat_priv->tt.changes_list);
Also what are differences between INIT_LIST_HEAD and INIT_HLIST_HEAD?

3)

Code: Select all

free_percpu(bat_priv->bat_counters);
what does free_percpu does?

4) list_for_each_entry_safe verus list_for_each_entry
what's safe means in this case?

5)

Code: Select all

seqno_event = malloc(sizeof(struct seqno_event));
	INIT_LIST_HEAD(&seqno_event->list);
	list_add_tail(&seqno_event->list, &orig_event->event_list);
can someone describe in word of what's happening above?

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: Some Linux Kernel codes

Tue Oct 07, 2014 6:38 am

First hit on Google for rtnl_link_register is
http://lxr.free-electrons.com/source/ne ... ink.c#L321

Code: Select all

/**
* rtnl_link_register - Register rtnl_link_ops with rtnetlink.
* @ops: struct rtnl_link_ops * to register
*
* Returns 0 on success or a negative error code.
*/
so rtnl_link_register is rtnetlink_link_register, first hit on Google for rtnetlink is
http://man7.org/linux/man-pages/man7/rtnetlink.7.html

Code: Select all

rtnetlink - Linux IPv4 routing socket
so rtnetlink_link_register is "Linux IPv4 routing socket link register"

now you try using Google it's fun.
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6122
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Some Linux Kernel codes

Tue Oct 07, 2014 8:20 am

The linux kernel is well documented and will usually have a in-source description of such functions.

Look up linux kernel linked lists to help understand the last snippet.

Return to “C/C++”