Documente Academic
Documente Profesional
Documente Cultură
RandyDunlap
LinuxKernelDeveloper, Mentor,andJanitor IEEENorthcon May19,2005
Copyright2005RandyDunlap,Allrightsreserved.
Agenda
Copyright2005RandyDunlap,Allrightsreserved.
Opensourcedevelopmentstyle,values,culture Linuxrapiddevelopmentcycle Linuxmaintainersandhierarchy Communicationsmethods Advantagesofhavingadriverinthemainlinekerneltree Codingstyle HowtosubmitLinuxkernelpatches Somebestknownpractices Legal/Licenses Testing WorkingintheLinuxkerneltree
3 Copyright2005RandyDunlap,Allrightsreserved.
Topics
MajorGoals
Encouragenewdevicedriverdevelopmentandsupport Drivercodemergedandmaintainedinmainline(GPL)
Copyright2005RandyDunlap,Allrightsreserved.
DevelopmentStyle,Values,andCulture
Copyright2005RandyDunlap,Allrightsreserved.
LinuxCulture
Committedtofollowingandusingstandards(e.g.,POSIX,IETF) Committedtocompatibilitywithothersystemsoftware Informaldesign/development:Notmuchexternalhighlevelproject planningordesigndocs(maybesomeinternallyatcompanies);can appeartobechaotic Newideasbestpresentedascode,notspecificationsor requirements RERO:ReleaseEarly,ReleaseOftenforcomments,help,testing, communityacceptance# Possibledownsides:flames,embarrassment
7 Copyright2005RandyDunlap,Allrightsreserved.
LinuxCulture(2)
LinuxCulture(3)
Copyright2005RandyDunlap,Allrightsreserved.
LinuxDevelopmentValues
Scratchyourownitch Weekenders>bigbusiness Code,nottalk Pragmatism,nottheory Thickskin Codeproducermakes[most] decisions Pride,principles,ethics, honesty Performance
Hardware&softwarevendor neutral Technicalmerit,notpolitics, who,ormoney Maintainability&aesthetics: cleanimplementation,not uglyhacks(codingsytle) Peerreviewofpatches (technical&style) Contributionsearnrespect
Copyright2005RandyDunlap,Allrightsreserved.
SomeThingstoAvoid
HowdoIinterceptasystemcall (orreplaceasyscalltable entry)? Makingdemandsinsteadof requests This{driver/feature}mustbe merged,it'simportanttoour company. Dateorreleaseversion requirements
Copyright2005RandyDunlap,Allrightsreserved.
10
SomeGoodTermstoUse
Tested...(howmanyconfigs) Buildson8architectures
11
Copyright2005RandyDunlap,Allrightsreserved.
WhenNewInfrastructureIsNeeded
Driverdeveloperscanhaveanimpactonkernelinfrastructure
DriversforNewHardware
NewDriverDevelopment
DevelopmentCycle
Movedfromsplitstable(2.even)anddevelopment(2.odd)trees causeddelayandbackportmania Nowacceptingdevelopmentpatchesintothemmpatchsetand movingthemtothemainlinekerneltreeafterashakeoutperiod (e.g.,2.6.11mm3) 2.6.xkernelversioncycle:makepatchesagainstLinus'stree (unlesstheyonlyapplytosomeothertreeorpatchset) Timebetween2.6.xreleases,intermediate2.6.xrcN Nightlysnapshots;automatedbuildsofreleases;commitsml 2.6.x.ystablekernelpatches
15 Copyright2005RandyDunlap,Allrightsreserved.
Linux2.6KernelTree&Branches
mainline 2.6.112.6.12rc12.6.12rc22.6.12rc32.6.12rc4.....2.6.12 mmpatchset:review/testherebeforemergeintomainline mm1mm1mm1mm1mm1 mm2mm2mm2 2.6.12rc3mm3 stablepatchseries 2.6.11.12.6.11.22.6.11.32.6.11.4.....2.6.11.9
16 Copyright2005RandyDunlap,Allrightsreserved.
MergestoMainline(withexceptions)
Mainlinekernel.org(Torvalds) mmpatchset(Morton) Subsystemmaintainers USB PPC XFS
SCSI
Block
Contributors(100s)
17
Copyright2005RandyDunlap,Allrightsreserved.
DevelopmentCycles
Rapiddevelopmentcycle,notimelines/schedules Onlyonlinedocumentationhasachanceofbeinguptodate Accommodatelargechangesandhighrateofchangewithout regressions Opendiscussion(mailinglists,archives,notprivate)# RERO,facilitatestestingonalargevarietyofplatforms# Maintainersavailableandaccessible,don'tdisappearforlong periodsoftime Testsuites Bugtracking
18 Copyright2005RandyDunlap,Allrightsreserved.
RatesofKernelChange
firstsixmonthsof2.4devel:220,000lines,+600,000lines firstsixmonthsof2.6devel:600,000lines,+900,000lines
1.5Mlineschangedina6.2Mlinetree 64MBdiffinsixmonthsandthat'sthestablekernel
Current2.6.11>2.6.12rc4(10weeks):729Klines,22MBdiff Current2.6.12rc4mm1patchset:414Klines,13MBdiff
19
Copyright2005RandyDunlap,Allrightsreserved.
Opensourcedevelopmentstyle,values,culture Linuxrapiddevelopmentcycle Linuxmaintainersandhierarchy Communicationsmethods Advantagesofhavingadriverinthemainlinekerneltree Codingstyle HowtosubmitLinuxkernelpatches Somebestknownpractices Legal/Licenses Testing WorkingintheLinuxkerneltree
20 Copyright2005RandyDunlap,Allrightsreserved.
Topics
MaintainersandHierarchy
Maintainers&Hierarchy(2)
22
Copyright2005RandyDunlap,Allrightsreserved.
Communications
Communicatingishard,let'sgoshopping Writingideas/thoughtsdownisgood(buttoowordymaybeignored) Participateconstructively Mailinglists&archives(newsgroups) Workinginopen/public(technicalreaders/writers)vs. embarrassment Discussionanddecisionsonlists,nomeetingsrequired Workthroughconcensus(withexceptions) Projectwebpages,IRCchannels Developerconferences
23 Copyright2005RandyDunlap,Allrightsreserved.
MailingListEtiquette
UseReplytoAll,threaded(MessageID,References)
MailingListEtiquette(2)
25
Copyright2005RandyDunlap,Allrightsreserved.
MailingListEtiquette:Notopposting
MailingLists
27
Copyright2005RandyDunlap,Allrightsreserved.
MoreKernelProjectMailingLists
28
Copyright2005RandyDunlap,Allrightsreserved.
MailingListsforLinuxStarters
MailingListArchives
Archivesforalmostall
http://www.kerneltraffic.org/summaries http://lwn.net/summaries
30
Copyright2005RandyDunlap,Allrightsreserved.
ProjectWebPages
31
Copyright2005RandyDunlap,Allrightsreserved.
DevelopmentConferences
32
Copyright2005RandyDunlap,Allrightsreserved.
RelatedDocumentation
WhyMergeIntotheMainlineKernelTree
BackgroundonkernelAPI/ABI
KernelAPIisnotstable;nokernelbinaryAPI(ABI) Astatic(stable)APIlimitsinnovationandaddscruft
Copyright2005RandyDunlap,Allrightsreserved.
AdvantagesofMergingintoMainline(1/3)
Keepsthedriverupdatedandworking,evenifitsmaintainer disappearsortheOEMstopssupporting/updatingit KernelAPIchangesaremergedforyou:performance improvements,bugfixes,securityfixes,parameterorstructure changes Kernelchangesincreasequalityofdriverwhilemaintenancecoststo themaintainerdecrease(areamortized) Otherpeoplewilladdfeaturestoyourdriver Otherswillfind&fixbugsinyourdriver Otherswillfind&fixperformance/tuningopportunities
35 Copyright2005RandyDunlap,Allrightsreserved.
MoreMergeAdvantages(2/3)
DriverisautomaticallyshippedinallLinuxdistroswithout havingtoaskdistrostomerge&shipitsoallstayinsync Driverisavailableforuseon20+CPUarchitecutures,notjusta handful[stillrequiresproperendianhandling;checkwith'sparse'] Drivergetbroadertestingandreview Drivermaintainerisrelievedfrommaintainingexternal patchsetsdifficultevenifopensourcecode Offersauniformfeaturesettoallusers Becomesthedefactodriver(withyouasMaintainer),keepingwork focusedononedriver
36 Copyright2005RandyDunlap,Allrightsreserved.
MergeAdvantages(3/3)
Severallargedistrovendorsrequireupstreamprogress(e.g., publicreviewsonmailinglists)
Mergingviadistroscanleadtoincompatibilitieswithmainline
Discouragesminiforking&fragmentation:badforusers(different features&bugs)&fortheforkmaintainer
Userswithnonmainlinedriverscanenduphelplessor unsupportedorlockedintoonedistro
37
Copyright2005RandyDunlap,Allrightsreserved.
DisadvantagesofMerging
Mustadaptcodetokernelcodingstyle Mustgothrupeerreviewandrespondtofeedback,makechanges Removecompatibilitylayers,oldkernelversionsupport,otherOS support Mayneedtomakeitarchportable(endianness,wordsizes) Mayneeddesignchangesorfeaturesadded Probablywilltakeseveralweeksofpostingpatches,feedback,more changes,butthat'saonetimething Costofnotlistening:investmanyearsindevelopmentthen toldthearchitectureiswrong,redoit
38 Copyright2005RandyDunlap,Allrightsreserved.
MergetoMainline(summary)
39
Copyright2005RandyDunlap,Allrightsreserved.
Opensourcedevelopmentstyle,values,culture Linuxrapiddevelopmentcycle Linuxmaintainersandhierarchy Communicationsmethods Advantagesofhavingadriverinthemainlinekerneltree Codingstyle HowtosubmitLinuxkernelpatches Somebestknownpractices Legal/Licenses Testing WorkingintheLinuxkerneltree
40 Copyright2005RandyDunlap,Allrightsreserved.
Topics
CodingStyle
Cleancode,notforotherOSesorforotherLinuxversions Usecomments,butnotforobviouscode;ondatastructures Drivers,filesystems,etc.,arenotarchspecific(mustbearch portable) Followstyleinsurroundingcode Veryminimaluseoftypedefs(onlyforbasictypes) Minimizeuseof#ifdefinCsourcefiles,usestubsinheaderfiles instead(asmuchaspossible/feasible) Documentation/:CodingStyle,SubmittingPatches/Drivers,&web pages
41 Copyright2005RandyDunlap,Allrightsreserved.
CodingStyle(2)
Don'tabusethekernelAPI Simplerisbetter(eschewobfuscation) Minimizemacrousage(preferinlinefunctionsfortypechecking) Stubs:include/linux/highmem.h,init.h,module.h,sched.h,swap.h, include/asmgeneric/dmamapping.h LinuxkerneliswritteninC,notC++ Use/*...*/forcomments(not//) Functioncommentsinkerneldocstyle Use(butdon'tabuse)'goto',especiallyforerrorhandling(one functionexitpath)[andundoallocationsetc.inerrorhandling]
42 Copyright2005RandyDunlap,Allrightsreserved.
CodingStyle(3)
$makeC=1...
CodingStyle(4)
Avoid'extern'inCfiles,useheadersinstead #includefileorder
Don't#includefilesunlesstheyareneeded/used
44
Copyright2005RandyDunlap,Allrightsreserved.
CodingStyle(5)(Policies)
CodingStyle(6)(Policies)
46
Copyright2005RandyDunlap,Allrightsreserved.
HowtoSubmitLinuxKernelPatches
47
Copyright2005RandyDunlap,Allrightsreserved.
SubmittingPatches(2)
48
Copyright2005RandyDunlap,Allrightsreserved.
register_chrdev() can return errors (negative) other then -EBUSY, so check for any negative error code. Signed-off-by: Randy Dunlap <rdunlap@xenotime.net> diffstat:= drivers/pcmcia/ds.c | 4 ++-1 files changed, 2 insertions(+), 2 deletions(-) diff -Naurp ./drivers/pcmcia/ds.c~ds_check_major ./drivers/pcmcia/ds.c --- ./drivers/pcmcia/ds.c~ds_check_major 2005-05-12 13:16:41.000000000 -0700 +++ ./drivers/pcmcia/ds.c 2005-05-12 19:45:36.000000000 -0700 @@ -1592,9 +1592,9 @@ static int __init init_pcmcia_bus(void) /* Set up character device for user mode clients */ i = register_chrdev(0, "pcmcia", &ds_fops); if (i == -EBUSY) if (i < 0) printk(KERN_NOTICE "unable to find a free device # for " "Driver Services\n"); "Driver Services (error=%d)\n", i); else major_dev = i;
49 Copyright2005RandyDunlap,Allrightsreserved.
+ +
SomeBestKnownPractices#
Trackorigin(s)ofyoursoftware(COO:CertificateofOrigin) UserDCO(Developer'sCertificateofOrigin)forkernelcontributions Managementapprovalandlegalclearancetosubmitsourcecode SomecompaniesmayrequireaWaiverofCopyright Sendpatchesdirectlytotheirintendedmaintainerformerging(they don'ttrollmailinglistslookingforpatchestomerge) Copypatchestotheappropriatemailinglist(s),notprivate(don't workinisolation) Subscribetorelevantmailinglists(oruseonerepresentativeforthis) Listentoreviewfeedbackandpromptlyrespondtoit
50 Copyright2005RandyDunlap,Allrightsreserved.
BestKnownPractices(2)#
Linusnormallydoesnotacknowledgewhenhemergesapatch Usecorrect'diff'directorylevel(linux/topleveldirectory)andoptions (up) Usesourcecodetoconveyideas Generatepatchfilesagainstthelatestdevelopmenttreebranch (rcN)ormainlinekernelifthereisnocurrentdevelopmentbranch Makefocusedpatchesoraseriesofpatches,notlargepatchesthat covermanyareasorthatjustsynchronizea(CVS)repositorywith thekernelsourcetree Usetheavailabledocs.
51 Copyright2005RandyDunlap,Allrightsreserved.
BestKnownPractices(3)#
IncludeCopyrightandlicense:MODULE_LICENSE(GPL); Useanemailclientthatsupportsinsertingpatchesinline(notas attachments) Beginwithsmallpatches:usekerneljanitorml Forlargerpatchesorcompletedriversorfeatures,usethekernel mentorsml(forbeginnerfeedback/comments/corrections) Don'tmisuse(abuse)thekernelAPI;e.g.,avoidvoid*function arguments Don'tpostprivateemailrepliestoapublicml(withoutpermission) Don'tintroducegratuitouswhitespacechangesinpatches
52 Copyright2005RandyDunlap,Allrightsreserved.
BestKnownPractices(4)#
Backupyourpatchwithperformancedata(ifapplicable) Don'taddbinaryIOCTLsunlesstherearenootheracceptable options;usesysfs(/sys)orprocfs(/proc)orprivatefsifpossible MakeLinuxdriversthatarenativeLinuxdrivers,notashimfrom anotherOS Don'tintroducekerneldriversifthesamefunctionalitycanbedone reasonablyinuserspace Trytobeprocessoranddistroagnostic(exceptforCPUspecific code) Don'tbeafraidtoacceptpatchesfromothers
53
Copyright2005RandyDunlap,Allrightsreserved.
BestKnownPractices(5)#
Keepyourpatch(es)updatedforthecurrentkernelversion Resubmitpatchesiftheyarenotreceivingcomments Releaseearly,releaseoften Open,publicdiscussiononmailinglists Onepatchperemail Largepatchesshouldbesplitintologicalpiecesandmailedasa patchseries Maketestingtoolsavailable&easytouse;yourdevice(s)willget bettertesting Givinghardwaretodeveloperscanresultindriverswrittenforyou
54
Copyright2005RandyDunlap,Allrightsreserved.
Opensourcedevelopmentstyle,values,culture Linuxrapiddevelopmentcycle Linuxmaintainersandhierarchy Communicationsmethods Advantagesofhavingadriverinthemainlinekerneltree Codingstyle HowtosubmitLinuxkernelpatches Somebestknownpractices Legal/Licenses Testing WorkingintheLinuxkerneltree
55 Copyright2005RandyDunlap,Allrightsreserved.
Topics
Legal&LicensePoints
IANAL,getlegaladvice Opensourceisabusinessdecision,freesoftwareisanethicalone All(internalorexternal)kernelmodulesmustbeopensource,GPL compatiblelicensed(dual) EXPORT_SYMBOL()andEXPORT_SYMBOL_GPL() http://www.opensource.orgOpenSourceInitiative,manyopen sourcelicenseslisted,butdesireistosignificantlyreducetonumber oflicensesthatareused Trackoriginsofsoftwareusedinternallyindevelopment UseDCOforLinuxkernelcontributions#
56 Copyright2005RandyDunlap,Allrightsreserved.
BugReportingandTracking
57
Copyright2005RandyDunlap,Allrightsreserved.
KernelTestProjects
58
Copyright2005RandyDunlap,Allrightsreserved.
VirtualizationforKernelTesting
59
Copyright2005RandyDunlap,Allrightsreserved.
WorkingintheLinuxKernelTree
60
Copyright2005RandyDunlap,Allrightsreserved.
KernelConfig
PatchMaintenanceTools
Use'patch'toapplypatchesthatyoucreateorreceive 'patchkernel'toupdatekerneldirectoryinplace
62
Copyright2005RandyDunlap,Allrightsreserved.
PatchTools(2)
Canuse'patchscripts'or'quilt'forpatchmanagement
http://www.zip.com.au/~akpm/linux/patches/patchscripts0.20/ http://savannah.nongnu.org/projects/quilt
63
Copyright2005RandyDunlap,Allrightsreserved.
References(1/3)
64
Copyright2005RandyDunlap,Allrightsreserved.
References(2/3)
65
Copyright2005RandyDunlap,Allrightsreserved.
References(3/3)
66
Copyright2005RandyDunlap,Allrightsreserved.
Credits
67
Copyright2005RandyDunlap,Allrightsreserved.