* size calculation wasted cpu time
@ 2009-03-16 13:02 Kuzin Andrey
2009-03-16 14:06 ` Pablo Neira Ayuso
2009-07-24 18:55 ` Jan Engelhardt
0 siblings, 2 replies; 6+ messages in thread
From: Kuzin Andrey @ 2009-03-16 13:02 UTC (permalink / raw)
To: netfilter-devel
In /net/netfilter/nfnetlink_queue.c every call of nfqnl_build_packet_message()
make series of call nla_total_size() for 'size' calculations.
I think 'size' is constant value for kernel build and may be define static
variable for this ?
Thank you.
static struct sk_buff *
nfqnl_build_packet_message(struct nfqnl_instance *queue,
struct nf_queue_entry *entry)
{
sk_buff_data_t old_tail;
size_t size;
size_t data_len = 0;
struct sk_buff *skb;
struct nfqnl_msg_packet_hdr pmsg;
struct nlmsghdr *nlh;
struct nfgenmsg *nfmsg;
struct sk_buff *entskb = entry->skb;
struct net_device *indev;
struct net_device *outdev;
size = NLMSG_SPACE(sizeof(struct nfgenmsg))
+ nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
#ifdef CONFIG_BRIDGE_NETFILTER
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
#endif
+ nla_total_size(sizeof(u_int32_t)) /* mark */
+ nla_total_size(sizeof(struct nfqnl_msg_packet_hw))
+ nla_total_size(sizeof(struct nfqnl_msg_packet_timestamp));
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: size calculation wasted cpu time
2009-03-16 13:02 size calculation wasted cpu time Kuzin Andrey
@ 2009-03-16 14:06 ` Pablo Neira Ayuso
2009-03-16 14:14 ` Patrick McHardy
2009-07-24 18:55 ` Jan Engelhardt
1 sibling, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2009-03-16 14:06 UTC (permalink / raw)
To: Kuzin Andrey; +Cc: netfilter-devel
Kuzin Andrey wrote:
> In /net/netfilter/nfnetlink_queue.c every call of nfqnl_build_packet_message()
> make series of call nla_total_size() for 'size' calculations.
> I think 'size' is constant value for kernel build and may be define static
> variable for this ?
We can calculate this during the module initialization, brave to cook a
patch for it?
--
"Los honestos son inadaptados sociales" -- Les Luthiers
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: size calculation wasted cpu time
2009-03-16 14:06 ` Pablo Neira Ayuso
@ 2009-03-16 14:14 ` Patrick McHardy
0 siblings, 0 replies; 6+ messages in thread
From: Patrick McHardy @ 2009-03-16 14:14 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Kuzin Andrey, netfilter-devel
Pablo Neira Ayuso wrote:
> Kuzin Andrey wrote:
>> In /net/netfilter/nfnetlink_queue.c every call of nfqnl_build_packet_message()
>> make series of call nla_total_size() for 'size' calculations.
>> I think 'size' is constant value for kernel build and may be define static
>> variable for this ?
>
> We can calculate this during the module initialization, brave to cook a
> patch for it?
The compiler should realize its constant and perform the calculation
at calculation time.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: size calculation wasted cpu time
2009-03-16 13:02 size calculation wasted cpu time Kuzin Andrey
2009-03-16 14:06 ` Pablo Neira Ayuso
@ 2009-07-24 18:55 ` Jan Engelhardt
2009-07-25 5:10 ` Re[2]: " Kuzin Andrey
1 sibling, 1 reply; 6+ messages in thread
From: Jan Engelhardt @ 2009-07-24 18:55 UTC (permalink / raw)
To: Kuzin Andrey; +Cc: netfilter-devel
On Monday 2009-03-16 14:02, Kuzin Andrey wrote:
>In /net/netfilter/nfnetlink_queue.c every call of nfqnl_build_packet_message()
>make series of call nla_total_size() for 'size' calculations.
>I think 'size' is constant value for kernel build and may be define static
>variable for this ?
>
> size = NLMSG_SPACE(sizeof(struct nfgenmsg))
> + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
> + nla_total_size(sizeof(u_int32_t)) /* ifindex */
> + nla_total_size(sizeof(u_int32_t)) /* ifindex */
The compiler will optimize it out.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re[2]: size calculation wasted cpu time
2009-07-24 18:55 ` Jan Engelhardt
@ 2009-07-25 5:10 ` Kuzin Andrey
2009-07-25 23:41 ` Henrik Nordstrom
0 siblings, 1 reply; 6+ messages in thread
From: Kuzin Andrey @ 2009-07-25 5:10 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: netfilter-devel
>>In /net/netfilter/nfnetlink_queue.c every call of nfqnl_build_packet_message()
>>make series of call nla_total_size() for 'size' calculations.
>>I think 'size' is constant value for kernel build and may be define static
>>variable for this ?
>>
>> size = NLMSG_SPACE(sizeof(struct nfgenmsg))
>> + nla_total_size(sizeof(struct nfqnl_msg_packet_hdr))
>> + nla_total_size(sizeof(u_int32_t)) /* ifindex */
>> + nla_total_size(sizeof(u_int32_t)) /* ifindex */
JE> The compiler will optimize it out.
Okey. It's easy to test.
=========== 1.c =======================
#include <stdlib.h>
#include <stdio.h>
#define NLA_ALIGNTO 4
#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
#define NLA_HDRLEN 30
static inline int nla_attr_size(int payload)
{
return NLA_HDRLEN + payload;
}
static inline int nla_total_size(int payload)
{
return NLA_ALIGN(nla_attr_size(payload));
}
size_t nfqnl_build_packet_message(int len) {
size_t size;
size = nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)); /* mark */
return size;
};
int main () {
long i;
size_t ret;
int r = 0;
for (i = 0; i < 100000000; i++) {
r = rand();
printf("%d",r);
ret = nfqnl_build_packet_message(r);
};
}
======================== end of 1.c ========================
And other case
===================== 2.c =============================
#include <stdlib.h>
#include <stdio.h>
#define NLA_ALIGNTO 4
#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
#define NLA_HDRLEN 30
static inline int nla_attr_size(int payload)
{
return NLA_HDRLEN + payload;
}
static inline int nla_total_size(int payload)
{
return NLA_ALIGN(nla_attr_size(payload));
}
size_t size_global = 0; ///// GLOBAL PRECALCULATED VALUE
size_t nfqnl_build_packet_message(int len) {
size_t size;
size = size_global;
return size;
};
int main () {
long i;
size_t ret;
//////// calculations here
size_global = nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)) /* ifindex */
+ nla_total_size(sizeof(u_int32_t)); /* mark */
int r = 0;
for (i = 0; i < 100000000; i++) {
r = rand();
printf("%d",r);
ret = nfqnl_build_packet_message(r);
};
}
===========================================
And some tests....
root@bill:/src/1# gcc 1.c
root@bill:/src/1# time ./a.out > /dev/null
real 0m20.253s
user 0m20.209s
sys 0m0.041s
root@bill:/src/1# gcc 2.c
root@bill:/src/1# time ./a.out > /dev/null
real 0m17.030s
user 0m16.988s
sys 0m0.040s
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Kuzin Andrey - kuzinandrey@yandex.ru
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Re[2]: size calculation wasted cpu time
2009-07-25 5:10 ` Re[2]: " Kuzin Andrey
@ 2009-07-25 23:41 ` Henrik Nordstrom
0 siblings, 0 replies; 6+ messages in thread
From: Henrik Nordstrom @ 2009-07-25 23:41 UTC (permalink / raw)
To: Kuzin Andrey; +Cc: Jan Engelhardt, netfilter-devel
lör 2009-07-25 klockan 09:10 +0400 skrev Kuzin Andrey:
> root@bill:/src/1# gcc 1.c
Now try the same with -O2
Regards
Henrik
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-07-25 23:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-16 13:02 size calculation wasted cpu time Kuzin Andrey
2009-03-16 14:06 ` Pablo Neira Ayuso
2009-03-16 14:14 ` Patrick McHardy
2009-07-24 18:55 ` Jan Engelhardt
2009-07-25 5:10 ` Re[2]: " Kuzin Andrey
2009-07-25 23:41 ` Henrik Nordstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).