From: Pekka Riikonen Date: Fri, 29 Mar 2002 20:47:42 +0000 (+0000) Subject: structure memory optimizations. X-Git-Tag: silc.client.0.8.6~4^2~55 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=6f6c6b1f52138ed5138c530614b24a503e542024 structure memory optimizations. --- diff --git a/CHANGES b/CHANGES index f355f383..a668b810 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,12 @@ +Fri Mar 29 21:55:41 EET 2002 Pekka Riikonen + + * Made some structure optimizations. SFTP memory FS MemFSEntry + entry structure. Optimized SilcTask structure. Optimized + SilcPacketContext structure. + + Affected files lib/silcsftp/sftp_fs_memory.c, + lib/silcutil/silcschedule.c, lib/silccore/silcpacket.h. + Fri Mar 29 10:41:07 EET 2002 Pekka Riikonen * And yet again reverted back the config thing since Johnny diff --git a/TODO-1.0 b/TODO-1.0 index afda54a9..4a0f6e2a 100644 --- a/TODO-1.0 +++ b/TODO-1.0 @@ -90,23 +90,6 @@ least could be done. SILC_BUFFER_LEN macro can do the same. These would save totally 8 bytes of memory per buffer. - o Scheduler can be optimized for FD tasks by changing the fd_queue - to SilcHashTable instead of using linked list. We need to do - one-to-one mapping of FD to task and hash table is more efficient - for this usage. - - Also redefine the silc_select to perhaps return a separate - structure of the events that actually occurred, instead of - returning the events in the fd_list which is then traversed - in the generic code to find the changed events. This can be - made faster by having own struct which includes only the - changed events, thus the tarversing is faster since the whole - fd_list is not traversed anymore (it is still traversed in the - silc_select but at least it removes one extra tarversing later - for the same list). - - Other task queues should be changed to use SilcList. - o Optimizations in Server o Remove the big switch statement from the function @@ -139,6 +122,8 @@ least could be done. o Rewrite SilcProtocol to be SilcFSM (see ~/silcfsm). + o Do some scheduler optimizations (see ~/silcschedule). + o Change SILC_TASK_CALLBACK to non-static, and remove the macro SILC_TASK_CALLBACK_GLOBAL. @@ -147,10 +132,6 @@ least could be done. o SILC RNG does not implement random seed files, and they should be implemented. - o Add SILC scheduler's internal routines into a table of implementation - function pointers, that the generic code then takes as extern from - implementation. These are the silc_schedule_internal_* routines. - o Cipher optimizations (asm, that this) at least for i386 would be nice. o Add builtin SOCKS and HTTP Proxy support, well the SOCKS at least. diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index e3c4b6ea..79123628 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -164,18 +164,20 @@ typedef unsigned char SilcPacketFlags; * * Short description of the fields following: * - * SilcBuffer buffer - * - * The data buffer. - * - * SilcPacketType type + * SilcUInt16 truelen * - * Type of the packet. Types are defined below. + * True length of the packet. This may be set by the caller before + * calling any of the silc_packet_* routines. If not provided the + * library will calculate the values. * * SilcPacketFlags flags * * Packet flags. Flags are defined above. * + * SilcPacketType type + * + * Type of the packet. Types are defined below. + * * unsigned char *src_id * SilcUInt8 src_id_len * unsigned char src_id_type @@ -190,15 +192,19 @@ typedef unsigned char SilcPacketFlags; * Destination ID, its length and type. On packet reception retuned * ID's are always the hash values of the ID's from the packet. * - * SilcUInt16 truelen * SilcUInt8 padlen * - * The true lenght of the packet and the padded length of the packet. - * These may be set by the caller before calling any of the - * silc_packet_* routines. If not provided the library will calculate - * the values. + * The padded length of the packet. This may be set by the caller + * before calling any of the silc_packet_* routines. If not provided + * the library will calculate the values. + * + * unsigned int long_pad + * + * If set to TRUE the packet will include the maximum padding allowed + * in SILC packet, which is 128 bytes. If FALSE only the amount of + * padding needed will be applied. * - * int users; + * unsigned int users; * * Reference counter for this context. The context is freed only * after the reference counter hits zero. The counter is added @@ -209,28 +215,29 @@ typedef unsigned char SilcPacketFlags; * * Packet sequence number. * + * SilcBuffer buffer + * + * The actual packet data. + * ***/ typedef struct { - SilcBuffer buffer; - SilcUInt16 truelen; SilcPacketFlags flags; SilcPacketType type; - SilcUInt8 padlen; unsigned char *src_id; + unsigned char *dst_id; SilcUInt8 src_id_len; SilcUInt8 src_id_type; - - unsigned char *dst_id; SilcUInt8 dst_id_len; SilcUInt8 dst_id_type; - int users; - bool long_pad; /* Set to TRUE to use maximum padding - in packet (up to 256 bytes). */ + SilcUInt8 padlen; + unsigned int long_pad : 1; /* Set when maximum padding in packet */ + unsigned int users : 23; /* Reference counter */ SilcUInt32 sequence; + SilcBuffer buffer; } SilcPacketContext; /****s* silccore/SilcPacketAPI/SilcPacketParserContext diff --git a/lib/silcsftp/sftp_fs_memory.c b/lib/silcsftp/sftp_fs_memory.c index 621fdee7..5ac53706 100644 --- a/lib/silcsftp/sftp_fs_memory.c +++ b/lib/silcsftp/sftp_fs_memory.c @@ -28,17 +28,16 @@ const struct SilcSFTPFilesystemOpsStruct silc_sftp_fs_memory; -/* Memory filesystem entry */ typedef struct MemFSEntryStruct { - char *name; /* Name of the entry */ - char *data; /* Data of the entry */ - bool directory; /* TRUE if this is directory */ - SilcSFTPFSMemoryPerm perm; /* Permissions */ struct MemFSEntryStruct **entry; /* Files and sub-directories */ - SilcUInt32 entry_count; /* Number of files and sub-directories */ + SilcUInt32 entry_count; /* Number of files and sub-directories */ struct MemFSEntryStruct *parent; /* non-NULL if `directory' is TRUE, includes parent directory. */ unsigned long created; /* Time of creation */ + char *name; /* Name of the entry */ + char *data; /* Data of the entry */ + unsigned int directory : 1; /* Set if this is directory */ + unsigned int perm : 7; /* Permissions */ } *MemFSEntry; /* File handle. */ diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 34538109..828e7874 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -109,12 +109,12 @@ do { \ /* SILC Task object. Represents one task in the scheduler. */ struct SilcTaskStruct { SilcUInt32 fd; - struct timeval timeout; - SilcTaskCallback callback; - void *context; - bool valid; - SilcTaskPriority priority; - SilcTaskType type; + SilcTaskCallback callback; /* Task callback */ + void *context; /* Task callback context */ + struct timeval timeout; /* Set for timeout tasks */ + unsigned int valid : 1; /* Set when task is valid */ + unsigned int priority : 2; /* Priority of the task */ + unsigned int type : 5; /* Type of the task */ /* Pointers forming doubly linked circular list */ struct SilcTaskStruct *next; diff --git a/lib/silcutil/silcschedule.h b/lib/silcutil/silcschedule.h index 1bc5d4a8..f10bd830 100644 --- a/lib/silcutil/silcschedule.h +++ b/lib/silcutil/silcschedule.h @@ -119,7 +119,7 @@ typedef struct SilcTaskStruct *SilcTask; typedef enum { /* File descriptor task that performs some event over file descriptors. These tasks are for example network connections. */ - SILC_TASK_FD, + SILC_TASK_FD = 0, /* Timeout tasks are tasks that are executed after the specified time has elapsed. After the task is executed the task is removed @@ -190,7 +190,7 @@ typedef enum { has expired only and only when every other task with higher priority has already been run. For non-timeout tasks this priority behaves same way. Life is not fair for tasks with this priority. */ - SILC_TASK_PRI_LOW, + SILC_TASK_PRI_LOW = 0, /* Normal priority that is used mostly in SILC. This is priority that should always be used unless you specificly need some other priority.